package com.epeer.dao;} <?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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd" default-autowire="byName"> <!-- =========================================================================================== --> <!-- 加载属性文件 --> <!-- =========================================================================================== --> <bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc-config.properties</value> </list> </property> </bean> <!-- =========================================================================================== --> <!-- 配置数据源 --> <!-- =========================================================================================== --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc_driver}" p:url="${jdbc_url}" p:username="${username}" p:password="${password}"/> <!-- =========================================================================================== --> <!-- 事务配置 --> <!-- =========================================================================================== --> <!-- Transaction manager for a single JDBC DataSource --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"/> <!-- 如果采用XML配置则用下面的配置 --> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.epeer.service.*Impl.*(..))" advice-ref="txAdvice"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" no-rollback-for="java.lang.Throwable"/> <tx:method name="remove*"/> <tx:method name="add*" no-rollback-for="java.lang.Throwable"/> <tx:method name="*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 如果采用XML配置则用上面的配置 --> <!-- 如果采用标注则去掉上面的配置,同时加入下面一行 --> <!-- <tx:annotation-driven transaction-manager="transactionManager"/> <!-- =========================================================================================== --> <!-- 事务配置 --> <!-- =========================================================================================== --> <!-- Transaction manager for a single JDBC DataSource --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"/> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- =========================================================================================== --> <!-- DAO配置 --> <!-- =========================================================================================== --> <bean id="userDao" class="com.epeer.dao.UserDaoImpl"/> <!-- =========================================================================================== --> <!-- Service配置 --> <!-- =========================================================================================== --> <bean id="userService" class="com.epeer.service.UserServiceImpl"/> 采用标注的话UserServiceImpl如下 package com.epeer.service;import org.springframework.transaction.annotation.Transactional;import com.epeer.dao.UserDao;@Transactional} 相关文章: 2021-11-07 2022-12-23 2022-12-23 2022-12-23 2021-12-22 2021-12-25 2022-12-23