spring context初始化时 增加自己的操作
我们要重写 contextInitialized这个方法
?
public void contextInitialized(ServletContextEvent event) {super.contextInitialized(event);//加入自己的操作}?
方法2
让你的service实现ApplicationListener接口
在onApplicationEvent(E event)方法中 写你自己的操作
?ContextRefreshedEvent?这个时间是bean初始化后调用的
?
onApplicationEvent(ContextRefreshedEvent? event){
????? //加入自己的操作
}
?
也可以这么写
onApplicationEvent(ApplicationEvent event){
?????? if(event instanceof ContextRefreshedEvent){
???????????? //加入自己的操作???
??? }
}
?
?
event事件介绍
ContextStoppedEvent? context停止事件
ContextRefreshedEvent? context bean加载完事件
ContextStartedEvent?? context开始事件
ContextClosedEvent?? context关闭事件
?
?
?