2014-04-04 53 views
13

我想一個Spring Web應用程序部署到Tomcat 7.0.24,但它與最後一行顯示爲在初始化春根的Tomcat 7個掛起的WebApplicationContext

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: [[email protected]f] 
Apr 4, 2014 1:38:30 PM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 

我最近升級到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> 

這裏是我的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/*"); 
    } 
} 

有什麼明顯的,我很想念?我已經檢查了有關此主題的所有其他問題/答案,但未找到解決方案。

+3

你打開Spring的日誌記錄了嗎?它說什麼? –

+1

打開Spring的日誌記錄最簡單的方法是什麼? –

+1

有了SLF4j,請參見[這裏](http://stackoverflow.com/questions/3387441/how-do-i-configure-spring-and-slf4j-so-that-i-can-get-logging)。 –

回答

21

爲此設置一個答案,以便其他人知道在這種特定情況下對我有什麼幫助。打開Spring日誌可以讓我看到數據庫連接處於掛起狀態。解決數據庫問題使我的應用程序能夠完成部署。

+0

解決了我的問題。我有一個在數據庫上運行的活動查​​詢。事情現在已經解決了 –

+0

什麼是數據庫連接的掛起狀態? – Stephane

+0

謝謝。這也是我的數據庫連接問題。 – rj4u

相關問題