<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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">
<!-- 加载外部的properties文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置组件扫描-->
<context:component-scan base-package="cn.xssq"/>
</beans>
下面两个就是必须要加的
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
上面都写好了最重要的的是下面这个:location属性填写的是resource下的properties文件名字
resource下的文件相当于编译后的class根目录下
<!-- 加载外部的properties文件-->
<context:property-placeholder location="classpath:jdbc.properties"/>
下面是使用xml配置组件扫描
<!-- 配置组件扫描-->
<context:component-scan base-package="cn.xssq"/>