Spring Framework (24 Part Series)
1 Spring Configuration
2 External Properties in Spring
… 20 more parts…
3 Profiles in Spring
4 Spring Expression Language (SpEL)
5 How Spring implements Singleton Beans
6 Converting explicit into implicit configuration in Spring
7 Autowiring in Spring
8 Lazy Beans in Spring
9 @PostConstruct and @PreDestroy in Spring
10 Stereotype and Meta Annotations in Spring
11 Spring’s FactoryBean Interface
12 The Spring Bean Lifecycle
13 Spring AOP
14 Caching in Spring
15 Spring JDBC
16 Spring Transaction Management
17 JPA with Spring
18 JPA with Spring Boot
19 Spring Web MVC
20 Spring Boot for war
21 Spring MVC REST
22 Reactive Spring Applications
23 Spring Security
24 Spring Injection Types
Initialization
ApplicationContext context = SpringApplication.run(AppConfig.class);
Enter fullscreen mode Exit fullscreen mode
- Load and process bean definitions: @Configuration classes are processed, @Components are scanned, XML files are parsed, bean definitions are added to a BeanFactory, BeanFactoryPostProcessor beans are invoked.
- Load bean definitions
- Post process bean definitions
- Perform bean creation (for each bean): each bean is eagerly instantiated by default (unless marked as lazy), each bean goes through a post-processing phase.
- Find and create its dependencies
- Instantiate beans (dependency injection)
- Call setters (dependency injection)
- Bean Post Processors
- BeforeInit: modify a bean before initialization
- Initializer: initialization methods are called (@PostConstruct, @resource, etc)
- AfterInit: modify a bean after initialization
- Bean ready for use
Usage
AppService service = context.getBean("appService", AppService.class);
service.doSomething();
Enter fullscreen mode Exit fullscreen mode
When you invoke a bean obtained from the context. If the bean is wrapped by a proxy the proxy is created during the initialization phase by a BeanPostProcessor adding behavior to the bean. It may be a JDK Proxy (interface based) or a CGLib Proxy (subclass based)
Destruction
context.close();
Enter fullscreen mode Exit fullscreen mode
The context is closed if the application shuts down (not killed or failed), all beans are cleaned up, @PreDestroy methods are invoked, beans are released for the Garbage Collector to destroy.
Spring Framework (24 Part Series)
1 Spring Configuration
2 External Properties in Spring
… 20 more parts…
3 Profiles in Spring
4 Spring Expression Language (SpEL)
5 How Spring implements Singleton Beans
6 Converting explicit into implicit configuration in Spring
7 Autowiring in Spring
8 Lazy Beans in Spring
9 @PostConstruct and @PreDestroy in Spring
10 Stereotype and Meta Annotations in Spring
11 Spring’s FactoryBean Interface
12 The Spring Bean Lifecycle
13 Spring AOP
14 Caching in Spring
15 Spring JDBC
16 Spring Transaction Management
17 JPA with Spring
18 JPA with Spring Boot
19 Spring Web MVC
20 Spring Boot for war
21 Spring MVC REST
22 Reactive Spring Applications
23 Spring Security
24 Spring Injection Types
暂无评论内容