我创建了一个新的 Spring boot 项目,并尝试实现一些 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 无法解析为类型
,对于其他注释和类(如 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>
关于java - 无法解析 Spring boot 项目中的 Spring AOP 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52289150/