问题:当AOP切入一个类的所有方法时,该类中的方法互相调用则只会增强最外层方法,被调用的方法不会增强
解决办法如下:
1.spring版本或较老的spring boot版本
解决方法是在applicationContext.xml中添加一段<aop:aspectj-autoproxy proxy-target-class="true"expose-proxy="true"/>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <aop:aspectj-autoproxy proxy-target-class="true" expose-proxy="true"/> </beans>
2.spring boot 版本
在ApplicationMain启动类加入@EnableAspectJAutoProxy(proxyTargetClass=true,exposeProxy=true)