gpt4 book ai didi

java - Mybatis Mapper工厂Bean和AOP

转载 作者:行者123 更新时间:2023-12-02 04:05:35 27 4
gpt4 key购买 nike

我正在使用 mybatis 3 开发一个 Web 应用程序,Spring 3.1.1-发布。我指的是the documentation .

MapperFactoryBean创建的数据访问层对象都不能被指向AOP的切入点。

我像这样编写了 spring 配置:

<bean id="memberDao" name="memberDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.musicovery.bookervery.dao.MemberDao" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

<!-- AOP Aspect -->
<bean id="customSqlExceptionTranslator" class="com.musicovery.bookervery.service.exception.CustomSqlExceptionTranslator" />

<!-- AOP Configuration -->
<aop:config>
<aop:advisor advice-ref="customSqlExceptionTranslator" pointcut="bean(memberDao)" />
</aop:config>

通过此配置,Eclipse 不显示 AOP 的切入点标记

mark

当我将切入点配置到另一个 bean 时,它可以工作。但只是由 MapperFactoryBean 创建的对象。

我想将 AOP 与 MapperFactoryBean 提供的数据访问层对象一起应用。

如何解决这个问题?

提前致谢

最佳答案

(1)切入 com.musicovery.bookervery.dao.MemberDao ,而不是 MapperFactoryBean 。(2)MapperFactoryBean是spring用来包装mybatis的mapper到spring bean的适配器。

所以可以这样实现事务aop:

<aop:config>
<aop:pointcut id="txPointcut"
expression="execution(public * com.musicovery.bookervery.dao.*.*(..))"/>
<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/>
</aop:config>

关于java - Mybatis Mapper工厂Bean和AOP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34311142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com