簡體   English   中英

Spring Boot AOP方面沒有被調用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM