无法在Spring启动项目中解析Spring AOP类型

问题描述 投票:0回答:2

我创建了一个新的Spring启动项目,并试图实现一些AOP问题。

但是,我的代码根本无法识别AOP中的类。我检查并确认spring-aop-5.0.7.RELEASE.jar确实存在于Maven依赖项和JRE运行时库中。

我的代码很简单:

@Aspect
@Component
public class LoggingAspect {

     @Around("execution(*  com.springboot.service.*(..)) ")
      public Object logAround(ProceedingJoinPoint joinPoint ) throws Throwable {

      }
}

但在这个代码Aspect cannot be resolved to a type和其他注释和类,如Joinpoint@Around相同。其他Spring注释和类工作完全正常,例如。 @ Component,@ Controller等等。项目本身在没有AOP的情况下运行良好。

我已经尝试过清理和重建项目了。

我能错过什么?任何帮助表示赞赏。

java spring-boot import spring-aop
2个回答
1
投票

@Aspect位于spring-aspects.jar或其中一个依赖。将其添加为依赖项:

<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>5.0.7.RELEASE</version>
</dependency>

1
投票

@Aspect@Around(以及其他此类)注释是org.aspectj aspectjweaver神器的一部分,这是一个optional compile dependency in your version of spring-aop

您必须明确包含它

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.8.13</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.