Search code examples
javaspringspring-mvcspring-annotations

do all @configuration classes need to be specified in either getRootConfigClasses or getServletConfigClasses?


In spring mvc project, I use purely java config style to configure the servlet container.

In a AbstractAnnotationConfigDispatcherServletInitializer subclass, I override two methods, getRootConfigClasses and getServletConfigClasses, they load beans for DispatcherServlet and ContextLoaderListener separately.

Do all @Configuration annotated classes need to be specified in either getRootConfigClasses or getServletConfigClasses, if no (probably), how and where the beans defined in those @Configuration classes are created and stored (in which application context)?


Solution

  • Not all Configuration classes need to be specified. Remaining can be @Imported in the Root or web config class