我创建了一个新的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的情况下运行良好。
我已经尝试过清理和重建项目了。
我能错过什么?任何帮助表示赞赏。
@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>