类型 [TYPE] 的 Bean 'x' 不符合被所有 BeanPostProcessor 处理的条件
Bean 'x' of type [TYPE] is not eligible for getting processed by all BeanPostProcessors
我有一个 ResourceAspect
class:
//@Component
@Aspect
public class ResourceAspect {
@Before("execution(public * *(..))")
public void resourceAccessed() {
System.out.println("Resource Accessed");
}
}
这是我的 Application
class:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.run(args);
}
}
项目中正在使用的依赖项是:
- spring-boot-starter
- spring-引导配置处理器
- spring-boot-starter-web
- spring-boot-starter-test
- spring-boot-devtools
- spring-boot-starter-security
- spring-boot-starter-aop
每当我将 @Component
添加到 ResourceAspect
时,resourceAccessed()
就会执行,但它也会抛出异常 Bean 'x' of type [TYPE] is not eligible for getting processed by all BeanPostProcessors
。没有 @Component
,resourceAccessed()
不执行。有什么想法吗?
我的猜测是您的切入点 execution(* *(..))
(基本上是 "intercept the world")影响了太多组件,甚至 Spring-内部组件。只需将其限制为 类 或您真正想要应用方面的包,例如
execution(* my.package.of.interest..*(..))
或
within(my.package.of.interest..*) && execution(* *(..))
如果更容易指定,您也可以排除不需要编织的那些:
!within(my.problematic.ClassName) && execution(* *(..))
或
!within(my.problematic.package..*) && execution(* *(..))
顺便说一句,当使用 Spring AOP(不是 AspectJ)时,当然你的方面需要是 @Component
。
我有一个 ResourceAspect
class:
//@Component
@Aspect
public class ResourceAspect {
@Before("execution(public * *(..))")
public void resourceAccessed() {
System.out.println("Resource Accessed");
}
}
这是我的 Application
class:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(Application.class);
springApplication.run(args);
}
}
项目中正在使用的依赖项是:
- spring-boot-starter
- spring-引导配置处理器
- spring-boot-starter-web
- spring-boot-starter-test
- spring-boot-devtools
- spring-boot-starter-security
- spring-boot-starter-aop
每当我将 @Component
添加到 ResourceAspect
时,resourceAccessed()
就会执行,但它也会抛出异常 Bean 'x' of type [TYPE] is not eligible for getting processed by all BeanPostProcessors
。没有 @Component
,resourceAccessed()
不执行。有什么想法吗?
我的猜测是您的切入点 execution(* *(..))
(基本上是 "intercept the world")影响了太多组件,甚至 Spring-内部组件。只需将其限制为 类 或您真正想要应用方面的包,例如
execution(* my.package.of.interest..*(..))
或
within(my.package.of.interest..*) && execution(* *(..))
如果更容易指定,您也可以排除不需要编织的那些:
!within(my.problematic.ClassName) && execution(* *(..))
或
!within(my.problematic.package..*) && execution(* *(..))
顺便说一句,当使用 Spring AOP(不是 AspectJ)时,当然你的方面需要是 @Component
。