Spring 引入属性文件
来源:互联网 发布:淘宝客店铺商品采集 编辑:程序博客网 时间:2024/06/05 19:39
示例代码:
在配置类上写上 @PropertySource
@PropertySource("classpath:application.properties")
注入成员变量的时候使用 @Value("${jdbc.jdbcUrl}")
另外,一定要注册一个 PropertySourcesPlaceholderConfigurer
@Beanpublic static PropertySourcesPlaceholderConfigurer propertyConfigure() { return new PropertySourcesPlaceholderConfigurer();}
如果引入的是 Spring 的核心配置文件,在类上写上注解:
@ImportResource(value="classpath:applicationContext.xml")
在核心配置文件里面引入属性文件的两种方法:
第 1 种:
<context:property-placeholder location="classpath:application.properties" />
第 2 种:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property></bean>
参考资料:
http://blog.chinaunix.net/uid-26209648-id-2435959.html
0 0
- Spring 引入属性文件
- Spring通过.properties文件引入属性配置
- spring学习笔记(5)属性文件引入使用
- spring引入非属性文件的两种方式
- spring引入properties文件,并在controller等层获得引入文件中属性的值
- spring引入properties文件,并在controller等层获得引入文件中属性的值
- Spring引入properties文件
- spring 引入properties文件
- Spring引入properties文件
- JFinal引入外部属性文件
- Spring中引入properties文件
- Spring中引入properties文件
- spring中引入其他文件
- spring引入外部properties文件
- spring boot 文件引入方式
- Spring整合Mybatis在引入属性文件的时候遇到的问题
- spring学习小结4——bean 的作用域 和引入外部属性文件
- 外部引入css文件,transition属性问题
- 关于ConcurrentHashMap
- 用Eclipse进行Java web开发时,错误:HttpServlet was not found on the Java
- HDU 1495 非常可乐(隐式图的遍历)
- 关于System V 消息队列介绍
- 修身养性的句子_关于修身养性的名言
- Spring 引入属性文件
- [Leetcode 234] Palindrome Linked List
- JSP九大内置对象
- HDU 1281 — 棋盘游戏 最大匹配
- 前端编码规范
- Swift学习笔记(八)——赋值运算符的返回值问题
- Centos7.1安装CUDA7.0
- 机房收费系统之准备工作
- W7启动报错0xc0000f