在项目开发的过程中遇到一些需要对一些常量进行自定义的情况,一般将这些自定义参数写入配置文件properties,项目运行时读取配置文件加载里面的参数。参考了一些网上对配置文件读取的方式,整理了以下几种方法。
一、通过context:property-placeholde实现配置文件加载
1、在spring.xml中加入context相关引用
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
2、引入jdbc的配置文件
<context:property-placeholder location="classpath:jdbc.properties"/>
j