In my spring application, I have the following configuration classes for the spring environment:
WebAppInitializer.java
@Order(value=1)
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";
}
}