XML-based configuration |
Annotation-based configuration |
Java-based configuration class |
|
Bean definitions |
<bean id="..." class="..." /> |
@Component @Repository derived classes @Service @Controller |
@Configuration label class, @ Bean Bean tagging method provided |
Bean name |
Specified by id or name |
@Component("person") |
@Bean("person") |
Bean injection |
<Property> or by p namespace |
@Autowired by type injection @Qualifier injected by name |
Injection internal write code logic method |
Life processes, Bean scope |
init-method destroy-method Range scope attribute |
@PostConstruct initialization @PreDestroy destruction @Scope setting scope |
Initialization method is called internally method @Scope specified range |
Suitable scene |
Bean from a third party, other namespaces |
Bean implementation class developed by the users themselves |
Examples of more complex logic Bean |
Reproduced in: https: //www.cnblogs.com/JsonShare/p/4630088.html