提问者:小点点

通知没有被编入跨模块的类文件中


我对AeyJ有问题,我想创建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");
    }
 }

一切都是用梯度建造的。我在模块记录器服务中添加了依赖项

  dependencies {
       compile project (":logger-client")
  }

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

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

此外,我还添加了模块记录器客户端作为依赖项添加到 IntelliJ 中的记录器服务。不幸的是,每个方法之前应该注入的建议在它在不同的模块中时没有注入。仅当我在记录器服务模块内移动Aspect类时,它才有效。

我尝试使用注释。我在logger-客户端模块中创建了“@Logger”注释,为建议添加了适当的切入点,并在“公共无效测试()”之前键入了此注释,但同样,Aspect没有正确注入。


共1个答案

匿名用户

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

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