2013-02-22 54 views
1

我跟着this example通過Java Spring的WebApplicationInitializer來配置我的DispatcherServlet - >javax.servlet.ServletContainerInitializerServletRegistration URL映射衝突

@Override 
public void onStartup(ServletContext servletContext) throws ServletException { 
    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); 
    mvcContext.register(MyConfiguration.class); 

    ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext)); 
    appServlet.setLoadOnStartup(1); 

    Set<String> mappingConflicts = appServlet.addMapping("/"); 
    if (!mappingConflicts.isEmpty()) { 
     for (String s : mappingConflicts) { 
      LOGGER.error("Servlet URL mapping conflict: {}", s); 
     } 
     throw new IllegalStateException("'appServlet' cannot be mapped to '/'"); 
    } 
} 

當我啓動Tomcat時,我得到上述IllegalStateException因爲apparently there is already a Servlet映射到/,我只能假設它是Tomcat的默認Servlet。如果我忽略映射衝突,我的DispatcherServlet未映射到任何內容。

有沒有什麼辦法覆蓋這個默認的servlet映射與我自己或我堅持映射我的DispatcherServlet/*

This answer通過更改您的應用程序在Catalina webapps文件夾中的部署位置提供了一個解決方案,但我希望能夠減少侵入性。

回答

0

所以原來可以在地圖上DispatcherServlet或通過Java上/任何其他的Servlet(而不是爲xml,你總是可以做到這一點),但只在Tomcat版本> 7.0.14,我是在7.0.12。

請參閱this Bugzilla issue討論。