无法解析 Spring 引导项目中的 Spring AOP 类型
Unable to resolve Spring AOP types in Spring boot project
我创建了一个新的 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、@Controllers 等。项目本身在没有 AOP 的情况下运行良好。
我已经尝试清理并重新构建项目。
我能少什么。感谢任何帮助。
@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>
@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>
我创建了一个新的 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、@Controllers 等。项目本身在没有 AOP 的情况下运行良好。
我已经尝试清理并重新构建项目。
我能少什么。感谢任何帮助。
@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>
@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>