1 比如我们在sc目录下新建一个db.properties文件内容如下
DriverClass=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
username = root
password =root
2把配置文件交给容器管理在applicationContext.xml加上这一句
<context:property-placeholder location="classpath:db.properties" file-encoding="utf-8"/>
3然后配置数据源的时候可以直接引用
<bean ></property>
</bean>
第二种方式
根据bean注入
<bean >
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
<property name="fileEncoding" value="UTF-8"></property>
<property name="ignoreResourceNotFound" value="true"></property>
</bean>