Java 未调用Spring引导AOP方面
我正试图用以下方式截获带有方面的rest服务调用Java 未调用Spring引导AOP方面,java,maven,spring-boot,spring-aop,aspect,Java,Maven,Spring Boot,Spring Aop,Aspect,我正试图用以下方式截获带有方面的rest服务调用 package mypackage.services.Service; @Component public class Service { @Override public Response helloService() { return handleResult("Hello test " + new Date()); } } 我使用以下maven依赖项 <dep
package mypackage.services.Service;
@Component
public class Service {
@Override
public Response helloService() {
return handleResult("Hello test " + new Date());
}
}
我使用以下maven依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.10</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
启动时,通过在ApplicationContext中记录bean,我可以看到正在创建方面类“AuditLog”
我已经设置了2个断点,但是调试器不会在“beforeServcie”方法处停止,而是在“helloService”处停止
我错过了什么?试试这个
execution(* mypackage.services.Service.*.*(..))
而不是
execution(* mypackage.services.Service.*(..))
试试这个
execution(* mypackage.services.Service.*.*(..))
而不是
execution(* mypackage.services.Service.*(..))
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
并且,不要将proxyTargetClass=true设置为默认值false
解释
格式为执行(..(..)
这里的包名是mypackage.services.Service,类名是Service
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
并且,不要将proxyTargetClass=true设置为默认值false
解释
格式为执行(..(..)
这里的包名是mypackage.services.Service,类名是Service。尝试过,但不起作用您不需要所有这些aspectj依赖项为什么有单独的xml配置?不需要proxyTargetClass=true哪些依赖项是多余的?我已经删除了targetClass=true,但它仍然不从Aspect Method传递ied,但它不起作用您不需要所有这些aspectj依赖项为什么您有一个单独的xml配置?proxyTargetClass=true不需要哪些依赖项是多余的?我已经删除了targetClass=true,但它仍然无法从Aspect方法传递如果您使用spring boot,则无需添加依赖项、config.xml和@enableSpectJautoprconfig Classis中的oxy(proxyTargetClass=true)如果我删除依赖项(即spring aop、aspectjrt),我会在“@Aspect”、“AfterReturn”和“@Before”注释上得到编译错误如果您使用spring boot,则无需添加依赖项,config classIf中的config.xml和@enableSpectJautoproxy(proxyTargetClass=true)将删除依赖项(即spring aop、aspectjrt),我在“@Aspect”、“AfterReturning”和“@Before”注释上得到编译错误,感谢3年后的回复。我从配置中删除了proxyTargetClass=true,并使用了@Before(“execution(*mypackage.services.Service.*(…)”),但没有得到任何运气:(@ahadutsegayabebe您说您尝试了
mypackage.services.Service.*
但建议的是mypackage.services.Service.*
对不起,我忘了提到我将包更正为“mypackage.services;”,感谢3年后的回复。我从配置中删除了proxyTargetClass=true,并在之前使用了@(“执行(*mypackage.services.Service.*(..)”)但运气不佳:(@ahadutsegayeabe您说您尝试了mypackage.services.Service.*
但建议的是mypackage.services.Service.*
对不起,我忘了提到我将程序包更正为'mypackage.services;'
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
execution(* mypackage.services.Service.Service.*(..))