简体   繁体   中英

mybatis mapper factory bean and aop

I am developing a web application with mybatis 3, Spring 3.1.1-RELEASE. I am referring the documentation .

None of the Data Access Layer objects created by MapperFactoryBean can be pointed as a pointcut of AOP.

I coded spring configuration like this:

<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>

With this configuration, Eclipse does not show a pointcut-mark of AOP

标记

When I configure the pointcut to another bean, it works. But just the objects created by MapperFactoryBean .

I want to apply AOP with Data Access Layer Objects provided from MapperFactoryBean.

How do I solve this ??

Thanks in advance

(1)pointcut to the com.musicovery.bookervery.dao.MemberDao , not the MapperFactoryBean. (2)the MapperFactoryBean is the adapter which spring use to wrapper mybatis mapper to spring bean.

so you can do like this to achieve the transaction aop:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM