springMVC子容器使用spring父容器配置文件资源
来源:互联网 发布:网络斗牛赌博作弊器 编辑:程序博客网 时间:2024/06/08 04:57
知识点:
1.子容器可以访问父容器的资源bean,父容器不可以访问子容器资源bean
2.spring配置读取配置文件属性例如jdbc.properties,父容器中可以使用@value("${key}") 对properties中的key获取其value值赋值给成员变量
@value注解 是在所有bean创建成功之后才执行,且只能在当前容器的查找数据
主要过程:
1.添加properties属性文件
2.spring配置文件配置读取该peoperties属性文件
3.在spring 中创建一个bean,使用@value读取并复制要使用的 key-value
4.将spring中的bean注入到springMVC容器中使用
详细过程:
子容器中使用父容器的properties配置文件变量:
设置配置文件 evn.properties
内容:PATH=D:\mysetup\images
URL=image.test.com
spring父容器配置文件加载applicationscontext.xml中读取该配置文件,配置如下
<!-- 使用spring自带的占位符替换功能 --><bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><!-- 允许JVM参数覆盖 --><property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /><!-- 忽略没有找到的资源文件 --><property name="ignoreResourceNotFound" value="true" /><!-- 配置资源文件 --><property name="locations"><list><value>classpath:env.properties</value></list></property></bean>
使用 @value注解 读取属性值 @value是在所有bean创建成功后再执行 @value注解只会在当前容器中查询数据
在spring父容器中读取属性文件中的值
@Servicepublic class PropertiesService {@Value("${URL}")public String PIC_MANAGE_URL;@Value("${PATH}")public String PIC_MANAGE_PATH;}
在将父容器中的bean注入到子容器中,子容器即可使用bean的属性值
@Autowiredprivate PropertiesService propertiesService ;
String fileFolder = this.propertiesService.PATH + File.separator + "images" ;
子容器中使用父容器的properties配置文件变量:
设置配置文件 evn.properties
内容:PATH=D:\mysetup\images
URL=image.test.com
spring父容器配置文件加载applications.xml中读取该配置文件,配置如下
<!-- 使用spring自带的占位符替换功能 --><bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><!-- 允许JVM参数覆盖 --><property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /><!-- 忽略没有找到的资源文件 --><property name="ignoreResourceNotFound" value="true" /><!-- 配置资源文件 --><property name="locations"><list><value>classpath:env.properties</value></list></property></bean>
1.1.1. @value注解
1. @value是在所有bean创建成功后再执行
2. @value注解只会在当前容器中查询数据
0 0
- springMVC子容器使用spring父容器配置文件资源
- springMVC子容器使用spring父容器配置文件资源
- spring 父子容器的概念(springmvc做父,子?容器)
- spring容器和springMVC容器
- springMVC容器和Spring容器
- springMVC容器和Spring容器
- springMVC容器和Spring容器
- SpringMVC容器和Spring Bean容器结合
- springmvc容器和spring容器的关系
- Spring的容器配置文件问题
- Spring与SpringMVC父子容器
- 自定义spring容器--spring容器读取bean配置文件的原理
- 使用Spring容器
- spring容器简单使用
- 如何获取SpringMvc对应的子容器?
- 获取SpringMvc对应的子容器
- Spring-----4、使用Spring容器
- Spring--Spring容器的使用
- Python学习(三)——条件语句
- 关于IntelliJ IDEA 控制台中文乱码问题
- 霍夫曼编码c++
- 【C/C++】VC++快捷键
- Android 实现视屏播放器、边播边缓存功能、外加铲屎(IJKPlayer)
- springMVC子容器使用spring父容器配置文件资源
- linux环境下mysql5.6的安装、配置、使用及常见问题解决办法
- 【linux系统】apt-get命令解析
- iOS——图片、界面的抖动
- [CSS]CSS/CSS3选择器
- 反射总结
- bootstrap常用的时间插件罗列及对比
- dyld: Library not loaded: /System/Library/Frameworks/UserNotifications.framework/UserNotifications
- 将 ICDAR 2015 的 Ground Truth 标注在图像数据上