Java Tomcat 7 挂起初始化 Spring 根 WebApplicationContext
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22871789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat 7 hangs on Initializing Spring root WebApplicationContext
提问by Matt Crysler
I am trying to deploy a Spring web application to Tomcat 7.0.24 but it hangs upon startup with the last lines showing as
我正在尝试将 Spring Web 应用程序部署到 Tomcat 7.0.24,但它在启动时挂起,最后几行显示为
INFO: Deploying web application archive /usr/local/apps/tomcat-7.0.42/webapps/server-webapp.war
Apr 4, 2014 1:38:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [com.verical.marketplace.init.MarketplaceWebAppInitializer@6a05fdf]
Apr 4, 2014 1:38:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
I recently upgraded to Spring 4.0.2 and am using a customer WebApplicationInitializer via annotations. Before the upgrade I was using Spring 3 with pure XML config and it worked just fine. My web.xml file looks like this:
我最近升级到 Spring 4.0.2 并通过注释使用客户 WebApplicationInitializer。在升级之前,我使用带有纯 XML 配置的 Spring 3,它工作得很好。我的 web.xml 文件如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
http://java.sun.com/xml/ns/javaee/web-common_3_0.xsd"
version="3.0">
<!-- Define the mime mappings -->
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<!-- Define the welcome file list -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Define the default session timeout value -->
<session-config>
<session-timeout>240</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
</session-config>
Here is my web application initializer:
这是我的 Web 应用程序初始值设定项:
public class MarketplaceWebAppInitializer implements WebApplicationInitializer
{
@Override
public void onStartup(ServletContext container)
{
// Instantiate a new web application context
XmlWebApplicationContext rootContext = new MarketplaceXmlWebApplicationContext(container);
// Add the various listeners
container.addListener(new ContextLoaderListener(rootContext));
container.addListener(new RequestContextListener());
// Set the locations of the configuration files
rootContext.setConfigLocations(
new String[]
{
"applicationContext.xml",
"config/api-beans.xml",
"config/hibernate-beans.xml",
"config/security-beans.xml",
"config/service-beans.xml",
"config/settings-beans.xml",
"config/utility-beans.xml",
"config/mvc/web-beans.xml",
"config/jmx-beans.xml",
"config/ws/ws-beans.xml"
}
);
// Add the dispatcher servlet
ServletRegistration.Dynamic mvc =
container.addServlet("mvc", new DispatcherServlet(rootContext));
mvc.setLoadOnStartup(1);
mvc.setInitParameter("dispatchOptionsRequest", "true");
mvc.addMapping("/api/*");
mvc.addMapping("/html/*");
// Add the web services servlet
ServletRegistration.Dynamic ws =
container.addServlet("ws", new MessageDispatcherServlet(rootContext));
ws.setLoadOnStartup(2);
ws.setInitParameter("transformWsdlLocations", "true");
ws.addMapping("/service/*");
// Add the spring security filter
FilterRegistration.Dynamic springSecurityFilter =
container.addFilter("springSecurityFilterChain",
new DelegatingFilterProxy("springSecurityFilterChain"));
springSecurityFilter.addMappingForUrlPatterns(null, true, "/j_spring_security_check");
springSecurityFilter.addMappingForUrlPatterns(null, true, "/j_spring_security_logout");
springSecurityFilter.addMappingForUrlPatterns(null, true, "/api/*");
springSecurityFilter.addMappingForUrlPatterns(null, true, "/html/*");
// Add the static content filter
FilterRegistration.Dynamic staticContentFilter =
container.addFilter("staticContentFilter", new StaticContentFilter());
staticContentFilter.addMappingForUrlPatterns(null, true, "/static/*");
staticContentFilter.addMappingForUrlPatterns(null, true, "/generated/*");
// Add the logger filter
FilterRegistration.Dynamic loggerFilter =
container.addFilter("loggerFilter", new LoggerFilter());
loggerFilter.addMappingForUrlPatterns(null, true, "/api/*");
loggerFilter.addMappingForUrlPatterns(null, true, "/html/*");
}
}
Is there anything obvious that I am missing? I've checked all the other questions/answers on this topic and didn't find a solution.
有什么明显的我失踪了吗?我已经检查了有关此主题的所有其他问题/答案,但没有找到解决方案。
采纳答案by Matt Crysler
Setting an answer for this so others know what helped me in this particular situation. Turning on Spring logging allowed me to see that a database connection was in a hung state. Resolving the database issue allowed my application to finish deployment.
为此设置一个答案,以便其他人知道在这种特殊情况下是什么帮助了我。打开 Spring 日志记录让我可以看到数据库连接处于挂起状态。解决数据库问题使我的应用程序能够完成部署。
回答by Aditya Gupta
Had been trying to figure out this for a while.
一直试图弄清楚这一点。
The console got stuck at INFO: Initializing Spring DispatcherServlet 'dispatcherServlet'
控制台卡在 INFO: Initializing Spring DispatcherServlet 'dispatcherServlet'
Turns out that that was the last message and the service had already started. I was accessing the service on the wrong port.
原来这是最后一条消息,服务已经启动。我在错误的端口上访问了该服务。
Also, logging was not configured. So no logs showed up after the default output from spring.
此外,未配置日志记录。所以在 spring 的默认输出之后没有出现日志。