Clean • Professional
Bean Loading Architecture describes how Spring Boot discovers, creates, configures, injects, initializes, proxies, and manages beans inside the IoC container.
Spring Boot enhances Spring’s Container with:
Bean Loading is the internal process Spring uses to convert classes → bean definitions → actual objects, and then manage their entire lifecycle.
Spring Boot automates and optimizes this process via:
➡ This makes bean creation predictable, powerful, and extendable.
The Phases of Bean Loading Architecture explain how Spring Boot discovers, creates, and wires beans inside the IoC container before the application becomes ready.

Spring first identifies which classes should become beans.
Sources include:
@Component, @Service, @Repository, @Controller@Configuration + @Bean@ConditionalOnClass, etc.)Spring converts them into BeanDefinition objects containing:
Example: Component scanning
@Component
public class MyService {
public void serve() {
System.out.println("Service running");
}
}➡ Spring creates a BeanDefinition for MyService.
All BeanDefinitions are stored in:
👉 BeanDefinitionRegistry
This acts as Spring’s internal “bean metadata database.”
No beans are created yet.
Example: Conceptually, Spring has a “map” like:
BeanDefinitionRegistry:
"myService" -> BeanDefinition(MyService.class, scope=singleton)
Before beans are created, Spring modifies BeanDefinitions.
Examples:
ConfigurationClassPostProcessor → processes @ConfigurationPropertySourcesPlaceholderConfigurer → resolves ${}Example: Using property placeholder
@Value("${app.name}")
private String appName;
➡ Resolved by PropertySourcesPlaceholderConfigurer.
Spring loads and registers all BeanPostProcessors, which run during bean creation.
Used for:
@Autowired resolution@Qualifier logic@PostConstruct and @PreDestroyExample: Custom BeanPostProcessor
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) {
System.out.println("Before init: " + name);
return bean;
}
}Spring now begins creating actual objects for each bean.
Internally Spring uses:
Example:
MyService myService = new MyService(); // internally done by Spring➡ Bean objects come to life at this stage.
Once instantiated, Spring injects dependencies via:
@Autowired)Spring resolves:
@Qualifier@PrimaryExample
@Service
public class UserService {
@Autowired
private MyService myService;
public void process() {
myService.serve(); // dependency injected
}
}Spring executes bean lifecycle callbacks:
@PostConstructInitializingBean.afterPropertiesSet()@Bean(initMethod="..."))Example:
@PostConstruct
public void init() {
System.out.println("UserService initialized");
}Now Spring applies post-initialization logic, such as:
Example: AOP proxy
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.*.*(..))")
public void log() {
System.out.println("Method called");
}
}
➡ Spring wraps beans with proxies if required.
Spring stores and manages beans differently based on their scope:
Available only in web applications.
Bean lifetime depends on the web scope:
Example: Singleton vs Prototype
@Component
@Scope("prototype")
public class PrototypeBean {}
➡ Spring creates a new instance each time.
Spring gracefully destroys beans:
@PreDestroyDisposableBean.destroy()Example:
@PreDestroy
public void cleanup() {
System.out.println("Bean destroyed");
}These are the core systems that drive the bean loading and initialization process inside Spring.

Responsible for reading and registering metadata from multiple sources:
@Configuration classes@Component, @Service, etc.)Example (conceptual):
@Configuration
public class AppConfig {
@Bean
public MyService myService() {
return new MyService();
}
}➡ BeanDefinitionLoader reads this configuration and creates a BeanDefinition for myService.
This is the main engine of the IoC container:
Example (conceptual):
MyService service = beanFactory.getBean(MyService.class);
It is the central implementation behind all BeanFactory operations.
Specialized for injecting dependencies and preparing beans:
@PostConstruct, InitializingBean, etc.)Example:
@Autowired
private MyService myService;
A chain of processors applied to every bean:
AutowiredAnnotationBeanPostProcessorCommonAnnotationBeanPostProcessorExample:
@Component
public class CustomProcessor implements BeanPostProcessor {
@Override
public Object postProcessAfterInitialization(Object bean, String name) {
System.out.println("Processed: " + name);
return bean;
}
}
Used to modify or wrap beans before and after initialization.
Analyzes AOP-related annotations such as:
@Transactional@Async@CacheableIf needed, wraps the bean inside a proxy using:
Enables cross-cutting features like transactions, caching, and async execution.
Example:
@Transactional
public void performTransaction() { ... }
➡ Spring creates a proxy for the bean using the AOP Proxy System.
Scan Components (@Component, @Service, @Configuration etc.) - Spring detects candidate classes for beans using annotations or configuration.
Create BeanDefinitions (blueprints) - Spring converts detected classes into metadata objects describing how to create and manage beans.
Register BeanDefinitions in BeanFactory - BeanDefinitions are stored in the container, ready for instantiation.
Run BeanFactoryPostProcessors (Auto-configuration magic here) - Spring modifies bean definitions before creating beans (e.g., resolving placeholders, auto-config tweaks).
Register BeanPostProcessors - Middleware is registered to intercept beans before and after initialization.
Instantiate Bean (new keyword / CGLIB) - Spring creates actual bean objects using constructors or CGLIB proxies.
Inject Dependencies (@Autowired, @Value) - Spring resolves and injects dependencies into the bean fields, constructors, or setters.
Apply BeanPostProcessors (AOP proxies created here) - Beans are processed by post-processors, often wrapped with proxies for AOP features.
Initialize Bean (@PostConstruct) - Initialization callbacks are executed to prepare the bean for use.
Add to Singleton Cache (bean ready) - Fully initialized singleton beans are stored for reuse across the application.
Destroy Bean on Shutdown (@PreDestroy) - Spring calls cleanup methods and releases resources when the application shuts down.

It enables:
Without this architecture, Spring Boot would not be able to offer:
➡ Bean Loading is the foundation of Spring Boot’s magic.
Bean Loading Architecture is Spring’s internal engine that discovers components, registers metadata, creates bean objects, injects dependencies, applies AOP, initializes them, and manages their lifecycle.