简体   繁体   English

Spring Boot AOP方面没有被调用

[英]Spring boot AOP Aspect not being invoked

I'm trying to intercept rest service calls with an aspect in the following manner 我正在尝试以以下方式拦截方面的其余服务调用

 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());
     }
}

I'm using the following maven dependencies 我正在使用以下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>

This maven plugin 这个Maven插件

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>aspectj-maven-plugin</artifactId>
      <version>1.0</version>
    </plugin> 

And my configuration xml contains 而且我的配置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" />

also in the Application class I've added the following annotation 同样在Application类中,我添加了以下注释

  @Configuration
  @EnableAspectJAutoProxy(proxyTargetClass=true)
  public class Configuration{
   ...
  }

On startup, by logging beans in the ApplicationContext, I can see that the aspect class "AuditLog" is being created. 启动时,通过在ApplicationContext中记录Bean,我可以看到正在创建方面类“ AuditLog”。

I've set 2 breakpoints, but the debugger does not stop at the "beforeServcie" method but it does stop at the "helloService". 我已经设置了2个断点,但是调试器不会在“ beforeServcie”方法处停止,但是会在“ helloService”处停止。

What am I missing? 我想念什么?

Try this 尝试这个

execution(* mypackage.services.Service.*.*(..))

instead of 代替

execution(* mypackage.services.Service.*(..))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM