I`m trying to run a simple application with spring java based configuration on jboss, but no success. This application works fine both on jetty and tomcat. The jboss log loo
I had a similar problem with a Spring MVC project deployed to JBoss 7.1 with no web.xml.
According to Spring javadocs for WebApplicationInitializer, older versions of Tomcat (<=7.0.14) could not be mapped to "/" programmatically. Older versions of JBoss AS 7 have this same defect.
This was the source of my problem. I was registering the servlet via "/", but JBoss EAP 6.4 doesn't support this mapping programmatically. It only works via web.xml. I still wanted to use programmatic config, so I changed the mapping to "/*" instead of "/", and it fixed my issue.
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;
}
}
Note: This configuration is incompatible with JSP views. "/*" will supersede the servlet container's JSP Servlet. If you still rely on JSP views, I would recommend using web.xml to configure the DispatcherServlet instead of doing it programmatically; the web.xml configuration works with "/" correctly.
dispatcher
org.springframework.web.servlet.DispatcherServlet
1
contextConfigLocation
dispatcher
/