Spring Framework Core Components, IOC, AOP, Bean Lifecycle and Related Concepts
This article provides a comprehensive overview of the Spring framework, covering its core modules, version compatibility, core concepts such as IoC and AOP, proxy implementations, bean factories, lifecycle management, transaction handling, MVC architecture, Spring Boot, Spring Cloud, and common annotations for Java backend development.
1. Spring Core Components
Spring is a lightweight, non‑intrusive IoC (Inversion of Control) and AOP (Aspect‑Oriented Programming) framework. The table below shows the main Spring versions and the required JDK versions.
Spring Version
JDK Version
1.x
1.3 (dynamic proxy introduced)
2.x
1.4 (normal upgrade)
3.x
5 (annotation support)
4.x
6 (major release, Spring Boot 1.x supported)
5.x
8 (lambda, etc.)
Current Java development standard: Spring 5 + Spring Boot 2 + JDK 8 .
1.1 Spring Overview
Spring is the dominant Java framework that simplifies development, promotes good coding practices, and provides a rich set of reusable components.
IoC / DI support
AOP programming support
Declarative transaction support
Testing support via JUnit4 annotations
Integration (glue) for other frameworks such as Struts, Hibernate, MyBatis, Quartz
Simplifies difficult Java EE APIs (JDBC, JavaMail, RMI, etc.)
1.2 Spring Modules
The framework is modular. The essential module is Spring Core Container; all other modules are optional (about 20+).
Spring Core : basic IoC and DI. Spring Context : enhanced BeanFactory. Spring Web : web‑application support. Spring MVC : MVC implementation. Spring DAO : JDBC abstraction. Spring ORM : integration with ORM frameworks (Hibernate, iBatis, JDO). Spring AOP : aspect‑oriented programming.
2. IoC and AOP
IoC (Inversion of Control) and AOP are the two core concepts of Spring. IoC lets the container manage object creation and dependency injection, while AOP enables cross‑cutting concerns such as logging and security.
2.1 IoC
Spring registers all beans in its container and injects dependencies automatically, eliminating manual factory or builder code.
Implementation relies on reflection and XML/annotation parsing to read bean definitions, instantiate objects, and inject properties.
2.2 Context
The ApplicationContext builds on the Core container, providing internationalization, resource loading, validation, data binding, and type conversion.
Two main context implementations:
BeanFactory – basic container, limited features.
ApplicationContext – extends BeanFactory with enterprise‑level services.
2.3 AOP
AOP separates reusable concerns (e.g., logging, validation) from business logic, allowing dynamic weaving at compile‑time, load‑time, or runtime.
Spring AOP uses runtime dynamic proxies (JDK or CGLIB) and supports five advice types: @Before, @AfterReturning, @AfterThrowing, @After, and @Around.
3. JDK Dynamic Proxy vs. CGLIB
3.1 JDK Dynamic Proxy
Requires an interface, creates a proxy class via Proxy.newProxyInstance(), and delegates method calls through an InvocationHandler.
3.2 CGLIB Proxy
Uses bytecode generation (ASM) to subclass the target class, works without interfaces, but cannot proxy final methods.
<code>public interface FoodService { void makeNoodle(); void makeChicken(); }</code>
<code>public class FoodServiceImpl implements FoodService { ... }</code>
<code>public class JDKProxyFactory implements InvocationHandler { ... }</code>
<code>public class CglibProxyFactory implements MethodInterceptor { ... }4. Spring AOP vs. AspectJ
4.1 Spring AOP
Runtime weaving based on dynamic proxies; limited to Spring‑managed beans; easier to learn.
4.2 AspectJ
Compile‑time or load‑time weaving; supports fields, constructors, static initializers; more powerful but more complex.
5. BeanFactory and FactoryBean
BeanFactory is the original IoC container with limited features. ApplicationContext extends it. FactoryBean allows custom bean creation logic; the object returned by getObject() is exposed as the bean.
6. Spring Bean Lifecycle
Four phases: definition, initialization, usage, and destruction. Custom init/destroy methods can be defined via XML, @Bean(initMethod, destroyMethod), @PostConstruct, @PreDestroy, or by implementing InitializingBean and DisposableBean.
7. Design Patterns in Spring
Factory Pattern – BeanFactory / ApplicationContext.
Proxy Pattern – AOP implementation.
Singleton – default bean scope.
Template Method – JdbcTemplate, HibernateTemplate.
Decorator – dynamic data source routing.
Observer – Application events.
Adapter – HandlerAdapter, AOP advice adapters.
8. Circular Dependency and Three‑Level Cache
Spring resolves singleton circular dependencies using three caches: singletonObjects – fully initialized beans. earlySingletonObjects – early exposed bean instances. singletonFactories – factories for early exposure, enabling proxy creation.
9. Transaction Management
Spring provides programmatic ( TransactionTemplate) and declarative ( @Transactional) transaction management. Propagation behaviors include REQUIRED, SUPPORTS, MANDATORY, REQUIRES_NEW, NOT_SUPPORTED, NEVER, and NESTED. Isolation levels map to the underlying database (DEFAULT, READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE).
10. Spring MVC
Core components: DispatcherServlet, Handler, HandlerMapping, HandlerInterceptor, HandlerExecutionChain, HandlerAdapter, ModelAndView, ViewResolver.
Workflow: request → DispatcherServlet → HandlerMapping → Handler → HandlerAdapter → Controller → ModelAndView → ViewResolver → view rendering.
11. Spring Boot
Provides convention‑over‑configuration, embedded containers, auto‑configuration, starter dependencies, and simplifies project setup.
12. Spring Cloud
Enables microservice architecture with service registration/discovery, load balancing, circuit breaking, and integrates with Netflix OSS, Alibaba, or Dubbo/ZooKeeper.
13. Common Annotations
@Component, @Controller, @Service,
@Repository @Autowired,
@Qualifier @Bean, @Configuration,
@Import @Value, @PostConstruct,
@PreDestroySigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
