spring中注入属性文件中的值
来源:互联网 发布:免费交朋友软件 编辑:程序博客网 时间:2024/05/22 13:20
方法1:
1、属性文件配置
<!-- 获取properties中的值 --> <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:conf.properties</value> </list> </property> </bean> <!-- Spring的动态变量,能在bean中直接调用 --> <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties" ref="configProperties" /> </bean> <!-- 配置扫描包 --> <context:component-scan base-package="com.xxx.hyweb" />
2、使用
properties中SERVICE_URL=http://sxxxx.com
@Componentpublic class ConfUitl { @Value("#{configProperties['SERVICE_URL']}") private String url; public String getUrl(){ return url; } public void setUrl(String url){ this.url = url; }}
方法2:
1、配置
<util:properties id="propertyConfigurer" location="classpath:global.properties"/><context:property-placeholder properties-ref="propertyConfigurer" ignore-unresolvable="true"/>
2、使用
properties中test.key = 542421ae23d4f;
@Servicepublic class Service{ @Value("${test.key}") private String key;}
阅读全文
0 0
- spring中注入属性文件中的值
- spring @value标签从properties文件中注入属性值
- Spring 依赖注入:获取properties文件中属性值
- Spring中的属性注入
- spring中的属性注入
- spring中注入抽象类中的接口属性
- spring中注入抽象类中的接口属性
- spring中属性文件和配置文件的注入方式
- Spring中属性注入操作
- Spring属性注入(从外部属性文件注入)
- Spring高级注入之属性值注入
- Spring高级注入之属性值注入
- Spring高级注入之属性值注入
- 五、Spring容器中Bean的属性值的注入
- Spring中利用配置文件和@value注入属性值
- Spring中利用配置文件和@value注入属性值
- Spring 属性文件的注入管理
- Spring 注入属性值细节
- ipconfig不是内部命令或外部命令
- .Net WebService 创建时的出现的问题
- 获取DTP跑的request ID
- 不用 sysadmin 权限,普通账户访问EXCEL文件
- ExecutorService对象的shutdown()和shutdownNow()的区别
- spring中注入属性文件中的值
- 性能测试
- 个人信用,你了解多少?
- Redis的数据类型
- maven学习笔记(一) maven简介以及安装
- sewise视频直播
- numpy的求模模块 linalg在范数运算中的应用
- 学习记录---颤抖吧,hadoop!(三)----搭建伪分布式
- android NDK 之cmake的使用