配置文件:/项目名/src/main/resources/config/dev/jdbc.properties
cc.jdbc.driver=com.mysql.jdbc.Driver
cc.jdbc.url=jdbc\:mysql\://111.22.22.333\:3306/cc?useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=convertToNull
cc.jdbc.username=root
cc=123456
引入配置文件方法一(可以一次引入多个)
<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean>
引入配置文件方法二
<context:property-placeholder location="classpath:/jdbc.properties"/>
调用配置文件上的属性
<!-- 标注类型 的事务配置 如果使用注解事务。就放开 <tx:annotation-driven /> -->
<bean id="ccDataSource" class="com.alibaba.druid.pool.DruidDataSource"
destroy-method="close">
<property name="driverClassName" value="${ccrepayment.jdbc.driver}" />
<property name="url" value="${ccrepayment.jdbc.url}" />
<property name="username" value="${ccrepayment.jdbc.username}" />
<property name="password" value="${ccrepayment.jdbc.password}" />
</bean>
Done!