Spring DispatcherServlet初始化完成后如何调用方法
之后如何调用方法 [DispatcherServlet]框架服务 'org.springframework.web.servlet.DispatcherServlet-1881e0df': 初始化在4859毫秒内完成 我正在创建实现ApplicationListener的类Spring DispatcherServlet初始化完成后如何调用方法,spring,spring-mvc,spring-boot,spring-annotations,Spring,Spring Mvc,Spring Boot,Spring Annotations,之后如何调用方法 [DispatcherServlet]框架服务 'org.springframework.web.servlet.DispatcherServlet-1881e0df': 初始化在4859毫秒内完成 我正在创建实现ApplicationListener的类 @Component public class ApplicationContextListener implements ApplicationListener<ContextStartedEvent>
@Component
public class ApplicationContextListener implements
ApplicationListener<ContextStartedEvent> {
@Override
public void onApplicationEvent(ContextStartedEvent event) {
System.out.println("ApplicationContext was initialized or refreshed: "
+ event.getApplicationContext().getDisplayName());
}
}
但在DispatcherServlet完成后,ApplicationEvent仍然没有启动
任何人都知道这有什么问题吗?根据spring文档,ContextStartedEvent仅适用于ConfigurableApplicationContext接口
ContextStartedEvent在启动ApplicationContext时使用ConfigurableApplicationContext接口上的start方法发布。从这里开始意味着所有生命周期bean都会收到一个明确的开始信号。通常,此信号用于在显式停止后重新启动bean,但也可用于启动尚未为autostart配置的组件,例如,初始化时尚未启动的组件。您需要使用ContextRefreshedEvent。ContextStartedEvent仅适用于手动启动applicationContext的特定情况
有关ContextStartedEvent和ContextRefreshedEvent之间差异的更多信息,请参阅此页。如何启动应用程序上下文?@FitrahEllyFirdaus您可以检查发布的答案,看看是否有人可以接受吗?如果没有,您可以发布您需要的其他信息吗?@FitrahEllyFirdaus如果您遵循上述方法,您是否能够获得活动?