写一个类继承ApplicationListener,可以直接引用下述代码,然后调用相应的方法。
package com.linewell.system; import com.linewell.cache.ApplicationData; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; @Component public class InitializationProcessor implements ApplicationListener<ContextRefreshedEvent> { @Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { if (contextRefreshedEvent.getApplicationContext().getParent() == null) { System.out.println("run onApplicationEvent method"); //dosomething } } }
原文地址:https://www.cnblogs.com/chenmz1995/p/10204407.html
时间: 2024-10-04 16:01:05