2013-02-22 56 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讨论。