getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationConfigDispatcherServletInitializer

前端 未结 2 1420
难免孤独
难免孤独 2020-12-02 04:00

What is the difference between getServletConfigClasses() vs getRootConfigClasses() when extending AbstractAnnotationCo

2条回答
  •  广开言路
    2020-12-02 04:57

    Root Config Classes are actually used to Create Beans which are Application Specific and which needs to be available for Filters (As Filters are not part of Servlet).

    Servlet Config Classes are actually used to Create Beans which are DispatcherServlet specific such as ViewResolvers, ArgumentResolvers, Interceptor, etc.

    Root Config Classes will be loaded first and then Servlet Config Classes will be loaded.

    Root Config Classes will be the Parent Context and it will create a ApplicationContext instace. Where as Servlet Config Classes will be the Child Context of the Parent Context and it will create a WebApplicationContext instance.

    In your ConServlet Configuration, You don't need to specify the @EnableWebMvc as well the InternalResourceViewResolver bean as they are only required at the WebConfig.

提交回复
热议问题