spring mvc;contextConfigLocation加载顺序
我正在重新配置一个webapp。我想将所有内容从DispatcherServlet移到ContextLoaderListener中。(这是由于安全配置的更改超出了此问题的范围) 问题1,如果我有多个应用程序上下文xml文件,它们的加载顺序是否重要?例如,在指定DAO和服务bean的xml文件之前,是否需要加载包含context:component scan的xml文件 问题2,(或者这是没有意义的?)假设A\U applicationContext.xml应该在B\U applicationContext.xml之前加载,而B\U applicationContext.xml应该在C\U applicationContext.xml之前加载,我将如何指定加载*\U applicationContext.xml的顺序 我的web.xml如下所示:spring mvc;contextConfigLocation加载顺序,spring,spring-mvc,Spring,Spring Mvc,我正在重新配置一个webapp。我想将所有内容从DispatcherServlet移到ContextLoaderListener中。(这是由于安全配置的更改超出了此问题的范围) 问题1,如果我有多个应用程序上下文xml文件,它们的加载顺序是否重要?例如,在指定DAO和服务bean的xml文件之前,是否需要加载包含context:component scan的xml文件 问题2,(或者这是没有意义的?)假设A\U applicationContext.xml应该在B\U applicationCo
评估交付
org.springframework.web.servlet.DispatcherServlet
1.
评估交付
/
上下文配置位置
/WEB-INF/config/*\u applicationContext.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
一些建议:
现在考虑通过JavaCon Fig.< /P>进行Spring的配置。
回答问题1和2非常重要,您必须了解以下内容:
- 运行应用程序时,Spring会创建一个
,其中存在Spring创建和管理的所有bean。现在,考虑到代码<应用程序上下文< /代码>,应该从两个“子”应用程序上下文创建,通常它们在文档中是如何被提及的:<代码> ServelAppultEngult和<代码> RootApplicationContext < /代码>应用程序上下文
- 前者应该扫描所有关于Web的信息,例如您的
和@Controller
关于基础设施的信息,例如@Bean
等李>viewsolver
- 后者应该扫描所有关于服务器的信息,例如
和@Service
以及@Repositories
关于基础设施的信息,例如@Bean
等数据源
- 前者应该扫描所有关于Web的信息,例如您的
-->ServletApplicationContext
RootApplicationContext
- 这意味着前者可以访问后者(它是关于使用依赖关系的,即:一个
需要一个@控制器
)。因此,它反映了@服务
端可以访问Web
端服务器
- 这意味着前者可以访问后者(它是关于使用依赖关系的,即:一个
-->RootApplicationContext
ServletApplicationContext
- 没有感觉到来自服务器端的Bean想要访问web端(一种糟糕的做法)
web.xml
但是
+DispatcherServlet
(通过contextConfigLocation
)表示ServletApplicationContext
+ContextLoaderListener
(通过contextConfigLocation
)表示RootApplicationContext
XML
JavaConfig
- 注释
等@Controller
.xml
文件(在您的情况下)是如何声明的(关于顺序)