java – Tomcat 7挂起初始化Spring根WebApplicationContext

前端之家收集整理的这篇文章主要介绍了java – Tomcat 7挂起初始化Spring根WebApplicationContext前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将一个 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

我最近升级到Spring 4.0.2,并通过注释使用客户WebApplicationInitializer.在升级之前,我使用纯3 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>

这是我的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,"/j_spring_security_logout");
    springSecurityFilter.addMappingForUrlPatterns(null,"/api/*");
    springSecurityFilter.addMappingForUrlPatterns(null,"/html/*");

    // Add the static content filter
    FilterRegistration.Dynamic staticContentFilter =
            container.addFilter("staticContentFilter",new StaticContentFilter());
    staticContentFilter.addMappingForUrlPatterns(null,"/static/*");
    staticContentFilter.addMappingForUrlPatterns(null,"/generated/*");

    // Add the logger filter
    FilterRegistration.Dynamic loggerFilter =
            container.addFilter("loggerFilter",new LoggerFilter());
    loggerFilter.addMappingForUrlPatterns(null,"/api/*");
    loggerFilter.addMappingForUrlPatterns(null,"/html/*");
  }
}

有没有什么明显的,我失踪了?我已经检查了关于这个主题的所有其他问题/答案,没有找到解决方案.

解决方法

为此设定答案,以便其他人知道在这种特殊情况下帮助我.打开Spring日志记录允许我看到数据库连接处于挂起状态.解决数据库问题使我的应用程序能够完成部署.
原文链接:https://www.f2er.com/java/124060.html

猜你在找的Java相关文章