
我在没有web.xml的情况下将Spring MVC项目部署到JBoss 7.1时遇到了类似的问题。
根据Spring Javadocs for WebApplicationInitializer的介绍,Tomcat的旧版本(<= 7.0.14)无法以编程方式映射到“ /”。较旧的JBoss AS 7版本也有相同的缺陷。
这是我问题的根源。我通过“ /”注册了servlet,但是JBoss EAP 6.4不以编程方式支持此映射。它仅通过web.xml起作用。我仍然想使用编程配置,因此我将映射更改为
“ / *”而不是
“ /”,它解决了我的问题。
public class WebApplicationInitializerImpl implements WebApplicationInitializer { @Override public void onStartup(ServletContext container) throws ServletException { WebApplicationContext context = getContext(); Dynamic registration = container.addServlet("dispatcher", new DispatcherServlet(context)); registration.setLoadonStartup(1); registration.addMapping("/*"); } private WebApplicationContext getContext() { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation(AppConfig.class.getName()); return context; }}注意:此配置与JSP视图不兼容。“ / *”将取代Servlet容器的JSP Servlet。如果您仍然依赖JSP视图,我建议您使用web.xml来配置DispatcherServlet,而不要通过编程方式进行配置。web.xml配置可正确使用“ /”。
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value> </init-param></servlet><servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern></servlet-mapping>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)