对SpringMVC上下文容器配置的理解
来源:互联网 发布:阿依莲正品淘宝折扣店 编辑:程序博客网 时间:2024/06/06 01:21
1、在读程序的过程中有一个疑问:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
FilterSql filterSql = (FilterSql)webApplicationContext.getBean("filterSql");//获取bean
上面的程序中webApplicationContext 没有获取任何的xml配置文件,为什么可以获取authority_applicationContext.xml中的bean呢?
这个与以下配置有关:
在web.xml中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:authority_config/authority_applicationContext.xml
classpath:authority_config/authority_springSecurity.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
只要有以上的配置就可以用webApplicationContext 获取authority_applicationContext.xml中的bean了。
2、具体解释如下:
spring上下文容器配置
spring为我们提供了实现ServletContextListener接口的上下文初始化监听器:org.springframework.web.context.ContextLoaderListener
spring为我们提供的IOC容器,需要我们指定容器的配置文件,然后由该监听器初始化并创建该容器。要求你指定配置文件的地址及文件名称,一定要使用:contextConfigLocation作为参数名称。
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,/WEB-INF/jason-servlet.xml</param-value></context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
该监听器,默认读取/WEB-INF/下的applicationContext.xml文件。但是通过context-param指定配置文件路径后,便会去你指定的路径下读取对应的配置文件,并进行初始化。
其他的关于SpringMVC的理解,还可以查看下面的文章
http://www.cnblogs.com/brolanda/p/4265597.html
- 对SpringMVC上下文容器配置的理解
- SpringMVC上下文父子容器
- SpringMVC上下文父子容器
- SpringMVC上下文父子容器
- springmvc执行流程以及对spring应用上下文webApplicationContext理解
- 对SpringMVC的理解
- 个人对“进程上下文”和“中断上下文”的理解
- 对Linux内核进程上下文和中断上下文的理解
- 对Linux内核进程上下文和中断上下文的理解
- 对Linux内核进程上下文和中断上下文的理解
- Spring、SpringMVC及web容器的Context上下文
- 对Java中"上下文"(context)的理解
- 对android上下文和窗口的理解
- spring和springmvc父子容器的理解
- springMVC上下文 和 springIOC容器 关联详解
- SpringMVC的配置及理解
- 我对“词法环境”“执行上下文”的理解
- 对DCI(数据、上下文、交互)的理解
- idea快捷键
- Java创建和解析Json数据方法(三)——json-lib包的使用
- Spark 之 Row
- 2017.8.11 OSU 失败总结
- 【Spring】Spring Framework Reference Documentation中文版38
- 对SpringMVC上下文容器配置的理解
- Git--将服务器代码更新到本地
- 百度地图前端插件的获取
- C++知识点(4)
- Model
- MySql 批量更新语句
- 关于global index、local index、global partition index的适用场景
- idea debug技巧
- TPL