package ....utils; import javax.annotation.PostConstruct; import org.springframework.stereotype.Service; import org.springframework.stereotype.Component; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; @Service public class TomcatStart { @PostConstruct public void init(){ System.out.println("开始执行...."); } } @Component public class TomcatStart implements ApplicationListener<ContextRefreshedEvent>{ @Override public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { System.out.println("开始执行...."); } }