我可以在mybatis映射器上设置Spring AOP切入点吗?

时间:2018-06-22 02:08:41

标签: spring interface mybatis spring-aop mapper

<aop:pointcut id="logPointcut" expression="(execution(* net.com..a..*Controller.*(..))
                                         or execution(* net.com.a..*ServiceImpl.*(..))
                                         or execution(* net.com.a..*Mapper.*(..)) />

这是xml文件中的切入点设置

public interface UserMapper {
    List<UserVO> selectUser(UserVO userVO) throws Exception;
}

我想在界面中设置AOP切入点。 它们是由mybatis创建的。

上面的表达式不适用于映射器。

从根本上不可能吗?

1 个答案:

答案 0 :(得分:0)

这个问题在这里已经被问过数十遍了,总是被那些想使用Spring AOP的人问到,但从来没有真正地去麻烦它的文档,或者至少在发布问题之前先搜索StackOverflow。这样的开发人员如何生存?

简短的答案是:

  • 不,Spring AOP只能拦截Spring组件的方法。
  • 如果要拦截非Spring内容,请使用AspectJ。您可以在有或没有Spring的情况下使用它。如果要从Spring使用它,Spring手册会告诉您如何配置它。否则,AspectJ手册会告诉您。