//ContextRefreshedEvent ----spring 容器初始化完毕的一个事件,及监听加载完毕后的事件 public class ListenerTest implements ApplicationListener<ContextRefreshedEvent>{ //注入 要监听的对象 @Autowired private GroupByCourier groupByCourier; @Override public void onApplicationEvent(ContextRefreshedEvent event) { new Thread(()->{ while(true){ if(groupByCourier.getCourier()=="sea"){ System.err.println("do what you want "); // send() }else { try { Thread.sleep(100000); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); } }