java - 多次创建 ApplicationContext(在 struts + Spring 项目中)
问题描述
我有一个遗留系统,在 struts 1 和 spring 3 中,现在我需要将 spring 3 的版本升级到 5。我已经完成了几乎所有的事情,并且一切正常。当我启动tomcat服务器时,我只面临一个问题。
让我们看看代码:- 这是之前的 web.xml 配置,
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
升级版本后:-
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>servlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
现在,当我启动我的 tomcat 服务器时,会创建两次 applicationContext 环境。一个用于“org.apache.struts.action.ActionServlet”,第二个用于“org.springframework.web.context.ContextLoaderListener”
检查日志:
INFO: TLD skipped. URI: http://struts.apache.org/tags-nested is already defined
May 01, 2020 11:14:09 AM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
May 01, 2020 11:14:09 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2020 11:14:09 AM org.apache.catalina.core.ApplicationContext log
// First time
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Calling the CacheManager Constructor...
May 01, 2020 11:14:17 AM org.apache.catalina.core.ApplicationContext log
// Second time
INFO: Initializing WebApplicationContext for Struts ActionServlet 'servlet', module ''
May 01, 2020 11:14:19 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9090"]
May 01, 2020 11:14:19 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-9009"]
May 01, 2020 11:14:19 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 18889 ms
建议我如何解决这个问题。
解决方案
推荐阅读
- list - Haskell:列出所有公因数
- python - 通过在多个列中搜索多个记录值来创建 Pandas DF
- haskell - 如何解决加载模块中的 Haskell 错误?
- javascript - 预期来电数:>= 1 已接来电数:0
- multithreading - .net Core 中的 FileSystemWatcher-Event 和对 Com-Objects 的调用
- amazon-web-services - AWS resize 实例量给出 UnauthorizedOperation
- r - 一个数据帧的列对的内部连接取决于另一个数据帧中一列的值
- c# - 在同一个 Stream 上创建多个 StreamReader 的奇怪行为
- applescript - 如何编写这个苹果脚本
- java - 我们如何使用 Java NIO Api 流式传输 CSV 文件?