如何解决AOP在同类调用方法中无法切入的问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计248个文字,预计阅读时间需要1分钟。
问题:当AOP切入一个类的所有方法时,该类中的方法相互调用的时机只会在最外层方法增强,被调用的方法不会增强。
解决方案:1. spring版本或较老的spring boot版本,解决方法是在`application.properties`中添加配置。
问题:当AOP切入一个类的所有方法时,该类中的方法互相调用则只会增强最外层方法,被调用的方法不会增强
解决办法如下:
1.spring版本或较老的spring boot版本
解决方法是在applicationContext.xml中添加一段<aop:aspectj-autoproxyproxy-target-class="true"expose-proxy="true"/>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework.org/schema/beans" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xmlns:aop="www.springframework.org/schema/aop" xsi:schemaLocation="www.springframework.org/schema/beans www.springframework.org/schema/beans/spring-beans-3.0.xsd www.springframework.org/schema/aop 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)
本文共计248个文字,预计阅读时间需要1分钟。
问题:当AOP切入一个类的所有方法时,该类中的方法相互调用的时机只会在最外层方法增强,被调用的方法不会增强。
解决方案:1. spring版本或较老的spring boot版本,解决方法是在`application.properties`中添加配置。
问题:当AOP切入一个类的所有方法时,该类中的方法互相调用则只会增强最外层方法,被调用的方法不会增强
解决办法如下:
1.spring版本或较老的spring boot版本
解决方法是在applicationContext.xml中添加一段<aop:aspectj-autoproxyproxy-target-class="true"expose-proxy="true"/>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework.org/schema/beans" xmlns:xsi="www.w3.org/2001/XMLSchema-instance" xmlns:aop="www.springframework.org/schema/aop" xsi:schemaLocation="www.springframework.org/schema/beans www.springframework.org/schema/beans/spring-beans-3.0.xsd www.springframework.org/schema/aop 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)

