关于事务管理出现com.sun.proxy.$Proxy*** 解决方法

基于的注解来管理事务@Transactional 此注解打在方法上和类上都可以

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.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
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--  根据配置文件读取信息用于创建数据库连接池 -->

    <!--   创建数据库连接池 -->
    <bean id="ds" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
			             			  // 每个人的后缀名可能不太一样     
        <property name="url" value="jdbc:oracle:thin:@localhost:1521/orcl.navicat.com"></property> 
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>


    <!--   创建SqlSessionFactoryBean用于执行sql语句 -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="ds"></property>
    </bean>


    <!--   扫描映射文件创建代理对象 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.zt.dao"></property>
    </bean>

    <!--    创建事务管理器    -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <!--       注入数据源-->
        <property name="dataSource" ref="ds"></property>
    </bean>
    #   
<!--   配置环绕通知-->  //   如果是基于子类的话就需要配置这个方法    proxy-target-class   
//基于子类指的是  不是通过service接口直接调用的方法
 <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
</beans>

基于xml管理事务

<!--事务配置-->
<tx:advice transaction-manager="transactionManager" id="interceptor">
    <tx:attributes>
        <tx:method name="find*" read-only="true" propagation="SUPPORTS"/>
        <tx:method name="*" propagation="REQUIRED" read-only="false"></tx:method>
    </tx:attributes>
</tx:advice>
<!--    aop指定路径-->
    <aop:config proxy-target-class="true">
<!--        配置指定路径-->
        <aop:advisor advice-ref="interceptor" pointcut="execution(* com.zt.impl.*.*(..))"></aop:advisor>
    </aop:config>
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值