启动监听ApplicationListener

spring mvc 启动监听,实现ApplicationListener<ContextRefreshedEvent>接口,然后重载 onApplicationEvent(ContextRefreshedEvent arg0);在spring配置文件中添加对应的bean即可!

public class startBeanPostProcessor implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent arg0) { 
if (arg0.getApplicationContext().getParent() == null) {
System.out.println("加载初始化方法");
                }
}

}

在spring中添加bean 

<bean class="com.xxx.xxxx.startBeanPostProcessor "/>


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭