Difference between getRootConfigClasses and getServletConfigClasses

0

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[]{"/"};
        }

    }
    
asked by Gemasoft 21.03.2017 в 17:27
source

1 answer

1

The method getServletConfigClasses() returns the class used for the configuration of the web layer, example: Drivers, Views, etc., while getRootConfigClasses() returns the class used to configure the other layers of the application, example: Services , Access to data, etc.

It is possible to place all the configuration in the class returned by getRootConfigClasses() .

    
answered by 01.04.2017 / 15:43
source