建议未跨模块编入 class 文件

Advices aren't woven into class files across modules

我对 AspectJ 有疑问,我想创建 2 个 jar 文件。一个是带有方面和逻辑的文件,而第二个是带有 MVC 服务的文件。我有两个模块:

logger-client
logger-service

客户端模块内部

@Aspect
public class AspectTesting {

   @Pointcut("execution(* * (..))")
   public void allServices2() {
   }

   @Before("allServices2()")
   public void executee(JoinPoint joinPoint) {
       System.out.println("Advice woken" + joinPoint.getSignature().getName());
   }
}

和模块服务

 public class Server {
        public static void main(String[] args) throws IOException {
        SpringApplication.run(Server.class, args);
        testig();
        System.out.println("Hey");
    }

     public void testing() { 
         System.out.println("Aspect woken");
    }
 }

全部使用 gradle 构建。我在模块 logger-service

中添加了依赖项
  dependencies {
       compile project (":logger-client")
  }

并且我在两个 gradle 文件中添加了 AspectJ

 project.ext {
   aspectjVersion = '1.9.1'
 }
 apply plugin: 'aspectj'

我还添加了模块 logger-client 作为对 IntelliJ 中 logger-service 的依赖。 不幸的是,当它在不同的模块中时,应该在每个方法之前注入的建议并没有被注入。它仅在我将 Aspect class 移入 logger-service 模块时才起作用。

我尝试使用注释。我在 logger-client 模块中创建了“@Logger”注解,在建议中添加了适当的切入点并在 "public void testing()" 之前输入了这个注解 但同样,Aspect 没有正确注入。

我解决了这个问题。 在 Aspect class 完成工作之前添加“@Component”。所以现在看点 class 看起来像:

 @Aspect
 @Component
 public class AspectTesting {
      @Pointcut("execution(* * (..))")
      public void allServices2() {
      }

      @Before("allServices2()")
      public void executee(JoinPoint joinPoint) {
          System.out.println("Advice woken" + joinPoint.getSignature().getName());
      }
}