Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
xml配置:
<bean id="str" class="java.lang.String"> <constructor-arg value="string_1"/> </bean>
我想捕捉(挂钩)这个 bean 的创建和销毁时刻?
在扩展的类中使用用@PostConstruct和注释的方法。@PostDestroySomeClass
@PostConstruct
@PostDestroy
SomeClass
生命周期回调:
http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-reference/html/beans.html#beans-factory-lifecycle
@PostContruct 和 @PreDestroy 注释:
http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-reference/html/beans.html#beans-postconstruct-and-predestroy-annotations
您还可以实现自己的 BeanPostProcessor:
http://docs.spring.io/spring/docs/3.2.5.RELEASE/spring-framework-reference/html/beans.html#beans-factory-extension