db.password=fulee2014
db.url=jdbc:mysql://127.0.0.1:3309/haofangjia?characterEncoding=GBK
db.driverClass=com.mysql.jdbc.Driver
src下的项目名-context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 自动装配的业务类必须指定要装配的类所处的包 -->
<context:component-scan
base-package="com.cn.fuleehaofangjia.biz.impl,com.cn.fuleehaofangjia.dao.impl" />
<!-- 配置外部资源文件 --><!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:db.properties"></property> </bean> -->
<!-- 配置外部资源文件 多个文件使用"," -->
<context:property-placeholder
location="classpath:db.properties" />
<!-- c3p0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- ${外部资源文件中key} -->
<property name="user" value="${db.user}" />
<property name="password" value="${db.password}" />
<property name="driverClass" value="${db.driverClass}" />
<property name="jdbcUrl" value="${db.url}" />
</bean>
<!-- Spring中默认的连接池 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="root"/> <property name="password" value="admin"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property
name="url" value="jdbc:mysql:///springJdbc"/> </bean> -->
<!-- apache连接池 dbcp -->
<!--<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="username" value="root"/> <property name="password" value="admin"/>
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property
name="url" value="jdbc:mysql:///springJdbc"/> </bean> -->
<!-- Spring JdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
scope="prototype">
<constructor-arg ref="dataSource" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>