Working with multiple dispatcher servlets in a spring application

后端 未结 3 923
心在旅途
心在旅途 2021-02-09 14:18

In my spring application, I have the following configuration classes for the spring environment:

WebAppInitializer.java

@Order(value=1)
         


        
3条回答
  •  北海茫月
    2021-02-09 15:06

    If you are using spring 3.2 or above you can go with below code.

    Make different class for all the dispacher servlet with overriding getServletName() method, to avoid same name conflicts.

    public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    
            @Override
            protected Class[] getRootConfigClasses() {
                // TODO Auto-generated method stub
                return new Class[] { RootConfig.class };
            }
    
            @Override
            protected Class[] getServletConfigClasses() {
                // TODO Auto-generated method stub
                return new Class[] { WebConfig.class };
            }
    
            @Override
            protected String[] getServletMappings() {
                // TODO Auto-generated method stub
                return new String[] { "/config1/*" };
            }
        }
    
    
    
    
     public class WebAppInitializer2 extends AbstractAnnotationConfigDispatcherServletInitializer {
    
    
            @Override
            protected Class[] getRootConfigClasses() {
                // TODO Auto-generated method stub
                return new Class[] { RootConfig.class };
            }
    
            @Override
            protected Class[] getServletConfigClasses() {
                // TODO Auto-generated method stub
                return new Class[] { WebConfig2.class };
            }
    
            @Override
            protected String[] getServletMappings() {
                // TODO Auto-generated method stub
                return new String[] { "/config2/*" };
            }
    
               @Override
                protected String getServletName() {
                  // TODO Auto-generated method stub
                 return "config2";
             }
        }
    

提交回复
热议问题