Spring Java Config vs Jboss 7

前端 未结 8 1608
故里飘歌
故里飘歌 2020-11-28 14:41

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

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 15:21

    As per the answers provided by Michael R and István Pató, the servlet mapping in JBoss must be "/*", not "/". However, the other solutions cause @Component annotated objects to be instantiated twice. The following solves the double initialization by first calling super.onStartup and then adding another mapping for the dispatcher servlet:

    public class WebApplicationInitializerImpl implements WebApplicationInitializer {
        @Override
        public void onStartup(ServletContext container) throws ServletException {
            super.onStartup(container);
    
            Dynamic registration = (Dynamic) container.getServletRegistration(EmbeddedWebApplicationContext.DISPATCHER_SERVLET_NAME);
            registration.setLoadOnStartup(1);
            registration.addMapping("/*");
        }
    }
    

提交回复
热议问题