What is the fundamental difference between initializing the Spring configuration classes in getRootConfigClasses and getServletConfigClasses in the WebInitializer class?
I have tried changing the initialization of my configuration classes in both methods without different results, the theory says that they are different contexts but in both ways it works the same.
I would like to know what is the correct way or if it represents an impact on my project to have it one way or another.
@Configuration
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{SecurityConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{WebConfig.class, SwaggerConfig.class};
}
@Override
protected Filter[] getServletFilters() {
return new Filter[] {new DelegatingFilterProxy("springSecurityFilterChain")};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
This is how it works, for example:
@Configuration
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{WebConfig.class, SecurityConfig.class,SwaggerConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{};
}
@Override
protected Filter[] getServletFilters() {
return new Filter[] {new DelegatingFilterProxy("springSecurityFilterChain")};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}