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 ...
随机推荐
- python模块之hashlib加密
40.加密模块:hashlib 1. >>> import hashlib >>> ret1 = hashlib.md5() ...
- IE8 不支持Date.now()
Date.now() 返回1970 年 1 月 1日午夜与当前日期和时间之间的毫秒数. 以下是微软的描述: 在早于 Internet Explorer 9 的安装版本中不受支持. 但是,在以下文档模式 ...
- Markdown 测试
量化派业务参考代码 测试二级标题 如果 merchant_id 是外部白条,则执行相关逻辑 if(order.getMerchantId() == Constants.BaitiaoMerchant. ...
- BZOJ 1263 整数划分
Description 从文件中读入一个正整数\(n\).要求将\(n\)写成若干个正整数之和,并且使这些正整数的乘积最大. 例如,\(n=13\),则当\(n\)表示为\(4+3+3+3\)(或\( ...
- 定义任务打印gradle下载的jar包位置
//定义任务打印gradle下载的jar包位置task showMyCache { configurations.compile.each { println it }}
- Tautology
WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of th ...
- Zabbix的集中式监控
相对于传统的ZABBIX硬件系统级监控(CPU,内存,硬盘,网卡),应用级的监控就显得有些复杂了. 如果对不同的应该来不同的应用,配置会很多的. 如果我们能在一个指定的AGENT上监控所有的APACH ...
- Qt tip 网络请求 QNetworkRequest QJason 处理 JSON
http://blog.csdn.net/linbounconstraint/article/details/52399415 http://download.csdn.net/detail/linb ...
- c#:for循环;穷举,迭代 练习
一)穷举 1. 第x种买法:羽毛球拍xx个,羽毛球xx个,水xx瓶 2. 单位给发了一张150元购物卡,拿着到超市买三类洗化用品. 洗发水15元,香皂2元,牙刷5元.求刚好花完150元,有多少 ...
- 中文简体windows CMD显示中文乱码解决方案
因为重装系统,以前是英文的,现在的镜像文件是中文简体windows 10.所以只能将就使用. 下载了JDK,CMD 写了命令java,结果一堆乱码(问号???).发现System的locale默认设置 ...