2015-12-16 69 views
0

我正在用mybatis 3開發一個web應用程序, Spring 3.1.1-RELEASE。 我指的是the documentationmybatis mapper factory bean and aop

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提供的數據訪問層對象。

我該如何解決?

預先感謝

回答

2

(1)切入點到com.musicovery.bookervery.dao.MemberDao,而不是MapperFactoryBean。 (2)MapperFactoryBean是spring用來將mybatis映射器封裝到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>