org.springframework.context.ApplicationContextAware接口说明
来源:互联网 发布:linux怎样开启端口号 编辑:程序博客网 时间:2024/04/29 17:56
一、这个接口有什么用?
当一个类实现了这个接口(ApplicationContextAware)之后,这个类就可以方便获得ApplicationContext中的所有bean。换句话说,就是这个类可以直接获取spring配置文件中,所有有引用到的bean对象。
二、怎么用?
举个例子:
例如我有一个方法类AppUtil,这个方法类中需要使用到的ApplicationContext中的某个bean(companyService)。
1、因为spring要建立属于自己的容器,就必须要加载自己的配置文件。
这个时候,需要注册ContextLoaderListener或者这个类的子类。
在web.xml加上以下的信息:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当然,这样子的话只会读取默认路径下的application.xml配置文件的。如果需要读取特定路径下的配置文件。需要在web.xml中
添加如下信息。可以参考我的示例,指定配置文件,如下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/app-context.xml</param-value>
</context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/app-context.xml</param-value>
</context-param>
注意:<param-name>contextConfigLocation</param-name>是不能改变的。
0 0
- org.springframework.context.ApplicationContextAware接口说明
- org.springframework.context.ApplicationContextAware
- org.springframework.context.ApplicationContextAware
- org.springframework.context.ApplicationContextAware
- org.springframework.context.ApplicationContextAware
- org.springframework.context.ApplicationContextAware
- 讲解org.springframework.context.ApplicationContextAware
- java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解 .
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware用法详解
- org.springframework.context.ApplicationContextAware使用理解
- org.springframework.context.ApplicationContextAware使用理解
- nginx + uwsgi - 错误: nginx:504 Gateway Time out
- tomcat https 部署 server.xml配置
- Git忽略规则及.gitignore规则不生效的解决办法
- 双击放大缩小图片
- 看看机智的前端童鞋怎么防盗
- org.springframework.context.ApplicationContextAware接口说明
- WebView页面显示不全
- AVPlayer设置从哪儿开始播放
- 浅谈面向对象的理解
- weblogic命令
- Python中的字典dict
- VTK-7.1.0/Examples/Medical/Medical4例子运行
- (三) Maven多模块项目之间依赖配置
- 图论