如果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 />

 

相关文章:

  • 2021-08-18
  • 2021-05-30
  • 2022-01-05
  • 2021-05-28
  • 2021-11-14
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案