spring应用

1. 如何把一个创建的对象放到spring容器:应该理解为如何把一个对象创建出来并放到容器当中

1) FactoryBean (跟第三方jar包集成或者扩展spring);

2) @Bean (@Bean是为了0配置去做的);

3) context.getBeanFactory().registerSingleton() (鸡肋,如果放在容器初始化之后,其他bean依赖不上;放在容器初始化之前,其它的Bean则依赖不上了);

 

2.  ApplicationContextAware,BeanFactoryAware,@lookup,lookup-method

 

3.  执行生命周期回调

1) Methods annotated with @PostConstruct

2) afterPropertiesSet() as defined by the InitializingBean callback interface

3) A custom configured init() method

 

4.SpringContainer初始化后执行(启动和停止回调)

 

SmartLifecycle(Eureka源码中用到了)

 

 

原文地址:https://www.cnblogs.com/gendway/p/14249563.html