Java ServletRegistration url映射与Spring DispatchersServlet冲突

Java ServletRegistration url映射与Spring DispatchersServlet冲突,java,servlets,spring-mvc,servlet-3.0,Java,Servlets,Spring Mvc,Servlet 3.0,我随后使用Spring的WebApplicationInitializer-->javax.servlet.ServletContainerInitializer通过java配置了DispatcherServlet: @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext mvcContext

我随后使用Spring的
WebApplicationInitializer
-->
javax.servlet.ServletContainerInitializer通过java配置了DispatcherServlet:

@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 '/'");
    }
}   
@覆盖
启动时公共void(ServletContext ServletContext)引发ServletException{
AnnotationConfigWebApplicationContext mvcContext=新的AnnotationConfigWebApplicationContext();
mvcContext.register(MyConfiguration.class);
ServletRegistration.DynamicAppServlet=servletContext.addServlet(“appServlet”,新DispatcherServlet(mvcContext));
appServlet.setLoadOnStartup(1);
设置mappingConflicts=appServlet.addMapping(“/”);
如果(!mappingConflicts.isEmpty()){
for(字符串s:mappingConflicts){
错误(“Servlet URL映射冲突:{}”,s);
}
抛出新的IllegalStateException(“'appServlet'无法映射到“/”);
}
}   
当我启动Tomcat时,我得到上面的
非法状态异常
,因为它映射到
/
,我只能假设这是Tomcat的默认Servlet。如果忽略映射冲突,则我的
DispatcherServlet
不会映射到任何对象

是否有任何方法可以使用我自己的servlet映射覆盖此默认servlet映射,或者我无法将我的
DispatcherServlet
映射到
/*


通过更改您的应用程序在Catalina webapps文件夹中的部署位置提供了一个解决方案,但我希望它不那么具有侵入性。

因此,您可以通过Java映射
DispatcherServlet
/
上的任何其他Servlet(而不是xml,在xml中您可以始终这样做),但只有在Tomcat版本>7.0.14时,我才使用7.0.12

请参阅以进行讨论