Spring 中jdbc的配置檔案的編寫
<!-- dataSource 資料庫連線池-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="password" value="1234"></property>
<property name="url" value="jdbc:mysql://localhost:3306/spring"></property>
<property name="username" value="root"></property>
</bean>
<!-- 配置jdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事務管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置userdao -->
<bean id="userDao" class="cn.com.spring.jdbc.UserDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<!-- 配置代理物件 -->
<bean id="userproy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!-- 目標物件 -->
<property name="target" ref="userDao"></property>
<!-- 代理物件實現的介面 -->
<property name="proxyInterfaces" value="cn.com.spring.jdbc.IUserDao"></property>
<!-- 事務管理器 -->
<property name="transactionManager" ref="transactionManager"></property>
<!---配置事務的引數-->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!--User -->
<bean id="user" class="cn.com.spring.jdbc.User">
<property name="id" value="2"></property>
<property name="name" value="allain"></property>
<property name="password" value="6666"></property>
</bean>