1. 程式人生 > >Spring的jdbc的xml配置

Spring的jdbc的xml配置

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns="http://www.springframework.org/schema/beans"

xmlns:context="http://www.springframework.org/schema/context"     xmlns:aop="http://www.springframework.org/schema/aop"     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 ">

    <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">//連線池配置         <property name="driverClass" value="com.mysql.jdbc.Driver"></property>         <property name="jdbcUrl" value="jdbc:mysql:///test1"></property>         <property name="user" value="root"></property>         <property name="password" value="root"></property>     </bean>

    <bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">//jdbcRemplate         <property name="dataSource" ref="dataSource"></property>     </bean>

    <bean name="userDao" class="com.kd.jdbctemplate.UserDaoImpl">//配置實現類的bean,匯入jdbcTemplate         <property name="jd" ref="jdbcTemplate"></property>     </bean> </beans>