@Bean used in the method
@Bean annotation tells Spring This method returns an object. The object to be registered as a bean Spring application context, the method comprising the final generation logic bean instance. The following code:
@Bean
public CompactDisc sgtPeppers(){
return new CompactDisc();
}
By default, bean's ID and methods of the same name with @Bean, bean name generated by the above method would be: sgtPeppers. To name can be set to rename the other method, the name property may be provided; such as:
@Bean(name = "lonelyHeartsClubBand")
public CompactDisc sgtPeppers(){
return new CompactDisc();
}
Spring intercepts all calls to this method, and to ensure that the direct method returns the created bean, but not always be the actual call. Because the default Spring bean create is a single case.
@Bean also support the init-method and destory-method.
@Bean (name = "store", initMethod = "init", destoryMethod = "destory") of these two methods should be implemented inside the class
You can refer to the blog: https://blog.csdn.net/xhf852963/article/details/78079329