spring 读取properties的两种方法
一:直接使用context命名空间
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:log4j.properties" />
二:在配置文件中配置PropertyPlaceholderConfigurer
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties" />
</bean>
实例:
<!-- property-placeholder是一个属性遍历器,定位一个属性文件,属性文件存放的是jdbc一些连接数据 -->
<context:property-placeholder location="classpath:jdbc.properties" /> <!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="minIdle" value="${minIdle}" />
</bean>
spring 读取properties的两种方法的更多相关文章
- Java中spring读取配置文件的几种方法
Spring读取配置XML文件分三步: 一.新建一个Java Bean: package springdemo; public class HelloBean { private String hel ...
- Springboot读取配置文件的两种方法
第一种: application.yml配置中的参数: zip: Hello Springboot 方法读取: @RestController public class ControllerTest ...
- 关于spring读取配置文件的两种方式
很多时候我们把需要随时调整的参数需要放在配置文件中单独进行读取,这就是软编码,相对于硬编码,软编码可以避免频繁修改类文件,频繁编译,必要时只需要用文本编辑器打开配置文件更改参数就行.但没有使用框架之前 ...
- 外部读取Excel的两种方法
1.使用Epplus读取 下载地址为https://epplus.codeplex.com/,下载文件后引用Epplus.dll文件. 这个类库读取Excel方便快捷,但是它只能读取.xlsx类型的文 ...
- Java读取Properties的几种方法
本文转载自:http://blog.csdn.net/chjttony/article/details/5927613 每次用完每次忘相对与绝对...
- spring读取properties的几种方式
参考链接:http://www.cnblogs.com/zxf330301/p/6184139.html
- spring 配置文件 引入外部的property文件的两种方法
spring 的配置文件 引入外部的property文件的两种方法 <!-- 引入jdbc配置文件 方法一 --> <bean id="propertyConfig ...
- delphi 读取excel 两种方法
http://www.cnblogs.com/ywangzi/archive/2012/09/27/2705894.html 两种方法,一是用ADO连接,问题是Excel文件内容要规则,二是用OLE打 ...
- Java 获取*.properties配置文件中的内容 ,常见的两种方法
import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...
随机推荐
- java单点登录系统CAS的简单使用
转:http://blog.csdn.net/yunye114105/article/details/7997041 背景 有几个相对独立的java的web应用系统, 各自有自己的登陆验证功能,用户在 ...
- Unity3D移植Windows Universal App(Windows 8.1 及Windows Phone 8.1)版本遇到的坑
移植的情况以及遇到的问题: 1.选用的版本是最新的Unity5.0. 2.全屏播放视频Handheld.PlayFullScreenMoview的路径必须是全路径,并且前面要加上"ms-ap ...
- Yeoman:适合现代Web应用的现代工作流
Yeoman:适合现代Web应用的现代工作流 Yeoman是Google的团队和外部贡献者团队合作开发的,他的目标是通过Grunt(一个用于开发任务自动化的命令行工具)和Bower(一个HTML. ...
- Google研究员Ilya Sutskever:成功训练LDNN的13点建议
Google研究员Ilya Sutskever:成功训练LDNN的13点建议 摘要:本文由Ilya Sutskever(Google研究员.深度学习泰斗Geoffrey Hinton的学生.DNNre ...
- Biathlon Track
Codeforces Round #242 (Div. 2) D:http://codeforces.com/contest/424/problem/D 题意:给你一个n*m的矩阵,每个格子上面有个数 ...
- Dungeons and Candies
Zepto Code Rush 2014:http://codeforces.com/problemset/problem/436/C 题意:k个点,每个点都是一个n * m的char型矩阵.对与每个 ...
- STM8S 模拟I2C程序
STM8S的硬件I2C还是存在问题,不敢贸然使用. 于是决定用模拟I2C. #define SCL PE_ODR_ODR1 #define SDA PE_ODR_ODR2 #define SDAM P ...
- SQL Server 中的嵌套事务与@@TranCount(转)
在处理事务的时候,一般都用RollBack Transaction来回滚,但是如果在嵌套事务中这样使用的话,就会出现错误. 在SqlServer里,嵌套事务的层次是由@@TranCount全局变量反映 ...
- (转载)URL与URI的区别
(转载)http://blog.csdn.net/eagle51998/article/details/372052 1 URL(Uniform Resoure Locator:统一资源定位器)是W ...
- wchar_t与char、wstring与string的相互转换
个人倾向于使用优秀的开源库做这个. 最近使用boost进行转换,代码极其简单: boost::filesystem::path src(wchar_t); char = src.string().c_ ...