Spring的配置文件建议命名为:applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
">
<context:component-scan base-package="com.etc"/>
<context:annotation-config/>
<!-- 加载数据库连接信息的属性文件.propertites -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config/data.properties"></property>
</bean>
<!-- 配置数据源,数据源提供了与数据库连接的技术及连接池技术 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<!-- spring中的JDBC技术数据库的数据对象 JDBCTemplet -->
<bean id="jdbcTemplate" class="">
<!-- 指定数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
data.properties文件:
driver=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/myschool?characterEncoding\=utf-8
username=root
password=123
initialSize=5
maxActive=100
maxIdle=10
minIdle=5