1.Bean life cycle
-
Instantiation
-
Property assignment Populate
-
Initialization
-
Destruction
2. Common annotations for assembly beans? Component class annotations?
Answer: Bean autowiring: @Autowired @Resource Differences: ①autowried is an annotation of Spring, and Resource is an annotation of javax.annotation ②autowired is injected by type (byType) by default, and Resource is injected by name (byName) by default
Component class annotations: @Component: All components can be used. The other three annotations are marked and can replace the other three components. @Service: Marks this class as a business logic component. @Controller: Mark this class as a component in the control layer. @Repository: Mark this class as a component of the persistence layer (Dao layer).
3. Several ways to implement custom initialization and destruction methods:
Specify init-method and destroy-method through @Bean. Bean implements the InitializingBean and DisposableBean interfaces. Use @PostConstruct and @PreDestroy annotations. BeanPostProcessor interface, bean post-processor.
4. There are two ways to create objects:
How to choose how to create and manage objects
(Two methods, adding component scanning (four annotations) and adding @Bean annotations (used in conjunction with @Configuration configuration class annotations))
2. Only custom types can use component scanning. Of course, custom types can also use the `@Bean` method, but it is not recommended.
3. Non-customized types cannot use component scanning (because you cannot add component annotations to these types), and can only use the `@Bean` method.