Use Case Demonstration Example 1: @EnableXXX Annotation Usage In a Spring MVC project, adding the @EnableWebMvc annotation to a configuration class triggers Spring to automatically register a series of Spring MVC components, including HandlerMapping, HandlerAdapter, ViewResolver, and more. Example 2...
Inversion of Control (IoC) shifts the responsibility of object creation and lifecycle management away from the objects themselves, delegating it to an external container. Dependency Injection (DI) serves as the primary mechanism to achieve this, where required components are supplied to an object ra...
Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by enabling modularization of cross-cutting concerns — behaviors that span multiple classes, such as logging, security, or transaction management. Unlike OOP, which structures code around objects and inheritance, AOP all...
To use AOP in Spring, include the AspectJ weaver dependency in your project: <dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.4</version> </dependency> </dependencies> Method 1:...
Today, I want to discuss the @Transactional(readOnly = true) annotation provided by Spring. I'm bringing this up because there are many instances of @Transactional(readOnly = true) in my company's project code, and colleagues who have used it say that @Transactional(readOnly = true) improves perform...
Understanding the Bean Container Concept A Spring Bean container is responsible for managing the configuration and lifecycle of application objects. It allows you to define how each bean is created—whether as a singleton instance or a new instance per request—and how beans relate to and interact wit...
Default singleton scope for controllers Switching controllers to prototype scope How HTTP requests hit controllers: paralel vs. serial execution Building a singleton and stress-testing it for thread safety Appendix: Spring bean scopes Default behavior: controller are singletons In Spring MVC, class...
Spring MVC binds incoming HTTP data to controller method parameters with @RequestParam, @RequestBody, and @ModelAttribute, when each is appropriate, and how they differ in behavior and data sources. @RequestParam Purpose Read simple request parameters encoded as application/x-www-form-urlencoded Wor...
1. Thread-bound transaction context Spring coordinates transactional work by binding state to the current thread. The central utility is TransactionSynchronizationManager, which maintains per-thread structures such as: Resources: key/value map for things like DataSource → ConnectionHolder Registered...
Event-driven design lets components react to facts instead of polling or tightly coupling modules. After some action completes, you publish an event; interested listeners consume it and run their own logic. In classic patterns, this aligns with publish–subscribe and the observer pattern. Core pieces...