在spring启动后执行代码
时间:2019-02-27 14:16:20
收藏:0
阅读:142
如果spring的项目直接监听tomcat启动对于 操作来说有很大难度,bean没有初始化,接口不能直接调用等等,所以我们代码执行要在spring启动之后执行项目
package com.java7115; public class OrderHandlingTimer implements ApplicationListener<ContextRefreshedEvent> { private static Log logger1 = LogFactory.getLog("x");//记录日志 @Override public void onApplicationEvent(ContextRefreshedEvent event) { if (event.getApplicationContext().getDisplayName().equals("Root WebApplicationContext")) { //逻辑代码 } } }
将bean注册上
<bean id="wmsApplicationListener" class="com.java7115.OrderHandlingTimer"/>
原文:https://www.cnblogs.com/q1359720840/p/10443259.html
评论(0)