2016-04-10 14 views
0

次のコードでAbstractAnnotationConfigDispatcherServletInitializerの代わりにspring WebApplicationInitializerを使用しています。なぜSpring WebApplicationInitializer StandardContextは、開始直後にリロードしますか?

アプリケーションが最初に開始してからリロードし、次のログで再度開始します。

INFO: Initializing Spring root WebApplicationContext 
**************************false 
Apr 11, 2016 2:58:56 AM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'dispatcher' 
Apr 11, 2016 2:58:57 AM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["http-nio-8080"] 
Apr 11, 2016 2:58:57 AM org.apache.coyote.AbstractProtocol start 
INFO: Starting ProtocolHandler ["ajp-nio-8009"] 
Apr 11, 2016 2:58:57 AM org.apache.catalina.startup.Catalina start 
INFO: Server startup in 18577 ms 
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.StandardContext reload 
INFO: Reloading Context with name [/iamSystem] has started 
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.ApplicationContext log 
INFO: Destroying Spring FrameworkServlet 'dispatcher' 
Apr 11, 2016 2:59:07 AM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
Apr 11, 2016 2:59:07 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc 
WARNING: The web application [iamSystem] registered the JDBC driver [net.sourceforge.jtds.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 
Apr 11, 2016 2:59:08 AM org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading 


Apr 11, 2016 2:59:12 AM org.apache.jasper.servlet.TldScanner scanJars 
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. 
Apr 11, 2016 2:59:12 AM org.apache.catalina.core.ApplicationContext log 
INFO: Spring WebApplicationInitializers detected on classpath: [[email protected], [email protected]f] 
Apr 11, 2016 2:59:13 AM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring root WebApplicationContext 
**************************false 
Apr 11, 2016 2:59:21 AM org.apache.catalina.core.ApplicationContext log 
INFO: Initializing Spring FrameworkServlet 'dispatcher' 
Apr 11, 2016 2:59:22 AM org.apache.catalina.core.StandardContext reload 
INFO: Reloading Context with name [/iamSystem] is completed 

私はAbstractAnnotationConfigDispatcherServletInitializer

public class SpringWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { 

@Override 
protected Class<?>[] getRootConfigClasses() { 
    return new Class<?>[] { AppConfig.class }; 
    // return new Class[] { WebMvcConfig.class }; 
    // return null; 
} 

// Since we have a single DispatcherServlet here, we can add the WebConfig 
// to the root context and make the servlet context empty 
@Override 
protected Class<?>[] getServletConfigClasses() { 
    return new Class<?>[] { WebMvcConfig.class }; 
    // return new Class[] { }; 
    // return null; 
} 

@Override 
protected String[] getServletMappings() { 

    return new String[] { "/" }; 
} 

@Override 
protected Filter[] getServletFilters() { 
    return new Filter[] { new DelegatingFilterProxy("springSecurityFilterChain"), 
      new OpenEntityManagerInViewFilter() }; 
} 

// By default when the DispatcherServlet can't find a handler for a request 
// it sends a 404 response. However if its property 
// "throwExceptionIfNoHandlerFound" is set to true this exception is raised 
// and may be handled with a configured HandlerExceptionResolver 
@Override 
protected void customizeRegistration(ServletRegistration.Dynamic registration) { 
    boolean done = registration.setInitParameter("throwExceptionIfNoHandlerFound", "true"); // -> 
                          // true 
    if (!done) 
     throw new RuntimeException(); 
} 

} 

を使用している場合、サーバーに問題があるものだけを1時間

で成功を開始okですか?

答えて

0

あなたはそれが二回リロードする理由です、それを2回インスタンス化されています

// Register the Root application context 
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); 
. 
. 
. 
    // Register the Web application context 
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); 
    mvcContext.register(WebMvcConfig.class); 
+0

私webapplicationinitializerが続く春のドキュメントであるhttp://docs.spring.io/spring/docs/current/javadoc-api/org/ springframework/web/WebApplicationInitializer.html私は一度それを始めるために何を書くべきですか? –

関連する問題