[英]Spring boot AOP Aspect not being invoked
我正在尝试以以下方式拦截方面的其余服务调用
package mypackage.services.Service;
@Component
public class Service {
@Override
public Response helloService() {
return handleResult("Hello test " + new Date());
}
}
@Component
@Aspect
public class AuditLog {
@Before("execution(* mypackage.services.Service.*(..))")
public void beforeServcie(JoinPoint jp){
log.info("Before ",jp.getSignature().getName());
}
}
我正在使用以下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>
这个Maven插件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
而且我的配置xml包含
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="mypackage"/>
<aop:aspectj-autoproxy proxy-target-class="true" />
同样在Application类中,我添加了以下注释
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class Configuration{
...
}
启动时,通过在ApplicationContext中记录Bean,我可以看到正在创建方面类“ AuditLog”。
我已经设置了2个断点,但是调试器不会在“ beforeServcie”方法处停止,但是会在“ helloService”处停止。
我想念什么?
尝试这个
execution(* mypackage.services.Service.*.*(..))
代替
execution(* mypackage.services.Service.*(..))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.