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>

相关文章:

  • 2021-05-26
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2021-09-04
  • 2022-01-14
  • 2021-09-03
  • 2021-12-28
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案