我注册了一个 Spring ApplicationListener bean 来侦听 ContextRefreshed 事件。但出于某种奇怪的原因,我得到two致电onApplicationEvent(ContextRefreshedEvent)
上下文初始化完成时的方法。这是正常行为还是表明我的配置有问题?我使用 Jetty 8 作为我的 Servlet 容器。
我的相关web.xml配置如下
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/spring/spring-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
Thanks!
即使您没有为 DispatcherServlet 指定 contextConfigLocation,它仍然会创建一个子上下文,并且第二个刷新事件是针对该上下文的。使用 event.getApplicationContext() 找出事件所属的上下文。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)