[英]DispatcherServlet Config in Annotation Based web.xml
Please refer this Source before reading question(WebAppInitializer.class). 阅读问题(WebAppInitializer.class)之前,请参考此源 。 Is it mandatory to separately configure root config classes and DispatcherConfig class.Why there is two objects created for AnnotationConfigWebApplicationContext.
是否必须分别配置根配置类和DispatcherConfig类。为什么要为AnnotationConfigWebApplicationContext创建两个对象。 Can't we use single object to configure all the classes.
我们不能使用单个对象来配置所有类。 My Spring Version is 4.3.12 Release and I am referring to Spring MVC (not Spring Boot).
我的Spring版本是4.3.12发行版,我指的是Spring MVC(不是Spring Boot)。
The 2 different contexts are created for a reason and they serves different purpose. 出于某种原因创建了两个不同的上下文,它们有不同的用途。
So, 2 instances of AnnotationConfigWebApplicationContext
are created to register 2 contexts. 因此,创建了2个
AnnotationConfigWebApplicationContext
实例来注册2个上下文。
It must also be seen, how 2 contexts are registered with the container. 还必须看到如何在容器中注册2个上下文。
//root Context
AnnotationConfigWebApplicationContext rootContext = ...
container.addListener(new ContextLoaderListener(rootContext));
// Register and map the dispatcher servlet
AnnotationConfigWebApplicationContext dispatcherServlet = ...
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.