404 error using Spring MVC Java Config on JBoss

前端 未结 2 448
渐次进展
渐次进展 2021-01-14 13:53

I wrote a small Spring MVC application with Java Config. It is working perfectly fine on Tomcat but not on JBoss EAP 6.2. It gets successfully deployed on JBoss but I get th

2条回答
  •  醉话见心
    2021-01-14 14:38

    Was reading tutorial from SivaLabs, there was such a problem with running application on JBoss that work fine with tomcat. Problem was solving by changing DispatcherServlet mapping to "/app/*" . You can also try implementing WebApplicationInitializer instead of using abstract class. Here is example:

     @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            WebApplicationContext context = getContext();
            servletContext.addListener(new ContextLoaderListener(context));
            ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
            dispatcher.setLoadOnStartup(1);
            dispatcher.addMapping("/"); // i have a more or less big website, and can't see advantages by using "/*" mapping, this can be also a problem. 
        }
    
        private AnnotationConfigWebApplicationContext getContext() {
            AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
            context.setConfigLocations("ua.company.config.WebConfig", "ua.company.config.PersistenceConfig", "ua.company.config.SecurityConfig");
            return context;
        }
    

提交回复
热议问题