拦截Mybatis的mapper
一、背景 使用mybatis-spring之后,使用的就是mapper接口,可以直接当传统的DAO来使用,如果在mapper之上又包一层dao的话,则会使开发变得繁琐,改了mapper的xml之后,又得改mapper接口,之后还得改dao,再改service,非常不便利。 二、拦截mapper的两种配置 1、使用@Aspect注解 要去使用jdk的代理,否则代理不了mapper(即mybatis代理的mapper没有默认的构造器,cglib无法再给这个代理构造代理,会报如下错误org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy13]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy13) <!-- 启动对@Aspectj的支持 true为cglib