Spring3中用注解直接注入properties中的值
来源:互联网 发布:仿京东商城源码 php 编辑:程序博客网 时间:2024/06/05 19:30
在bean(可以是controller, service, dao等)中,使用@Value注解:
@Service
publicclass TmsRemoteService {
@Value("${tmsremoteservice.url}")
privateString url;
}
在spring配置文件里:
<!-- 将多个配置文件读取到容器中,交给Spring管理 -->
<beanid="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<!--这里支持多种寻址方式:classpath和file-->
<value>classpath:config.properties</value>
<!--推荐使用file的方式引入,这样可以将配置和代码分离 -->
<!--<value>file:/opt/demo/config/demo-mq.properties</value> -->
</list>
</property>
</bean>
config.properties文件:
tmsremoteservice.url =fdsafddsafsdadfd
这样config.properties中的tmsremoteservice.url就注入到url属性中了
PS:如果是在spring配置文件里注入需在方法中提供setter方法
<beanid="tmsRemoteService"
class="com.bsis2.work.logic.TmsRemoteService">
<property name="url">
<value>${tmsremoteservice.url}</value>
</property>
</bean>
- Spring3中用注解直接注入properties中的值
- Spring3中用注解直接注入properties中的值
- Spring3中用注解直接注入properties中的值
- spring3.0注解注入
- Spring3 注解注入详解
- spring注解注入properties属性值
- spring3.x注解自动注入
- Spring3中的@value注解
- Spring3.0注解注入(@Resource)
- spring3的注解注入 的注意事项
- Spring 通过注解注入Properties文件
- 跟我学Spring3--注解实现Bean依赖注入
- spring3注解方式无法注入servlet和filter
- Spring3.0中的AOP注解配置
- 注解注入xml中的类
- spring3注解
- spring3 注解
- spring3注解
- Shell脚本调用mysql语句
- 分布式中使用 Redis 实现 Session 共享(上)
- Android实战简易教程<二十四>(基于Baas的用户表查询功能实现!)
- 链表问题(二)——有序链表合并
- 实现九九乘法表
- Spring3中用注解直接注入properties中的值
- 使用VC++使用开发Web服务(ISAPI extension - mod_gsoap.dll)1
- Java编程【1】Define an interface called IAnimal,return 10 animals filled radndomly 3 kinds of animals
- CADisplayLink 和 NSTimer
- Android中插件开发篇之----动态加载Activity(免安装运行程序)
- 分布式中使用 Redis 实现 Session 共享(中)
- 机器学习经典论文/survey合集 - 算法组
- Android中ClearEditText实现点击EditText输入框右边清除图标来清除输入内容的两种方式
- 欢迎使用CSDN-markdown编辑器