Skip to content

Warning message about bean post-processing and eager injection may suggest the wrong cause #33184

Closed
@wilkinsona

Description

Affects: 6.1

While looking at the sample for #33180 I noticed several warning messages related to eager injection and bean post-processing:

2024-07-10T09:55:40.473+01:00  WARN 593 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'application.SecurityConfig.OAuthSecurityConfig' of type [org.example.testsb.Application$SecurityConfig$OAuthSecurityConfig$$SpringCGLIB$$0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.
2024-07-10T09:55:40.501+01:00  WARN 593 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'application.PermissionEvaluatorTest' of type [org.example.testsb.Application$PermissionEvaluatorTest] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.
2024-07-10T09:55:40.504+01:00  WARN 593 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityExpressionHandler' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.
2024-07-10T09:55:40.505+01:00  WARN 593 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'authorizationManager' of type [org.example.testsb.Application$SecurityConfig$OAuthSecurityConfig$$Lambda$464/0x000000013c380b58] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.
2024-07-10T09:55:40.507+01:00  WARN 593 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'authorizationEventPublisher' of type [org.springframework.security.authorization.SpringAuthorizationEventPublisher] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.

Each warning suggests that the declaration of healthEndpointGroupsBeanPostProcessor and its dependencies should be checked, but I don't think it's the culprit. In each case, the stack when the warning is logged is the following:

Thread [main] (Suspended (breakpoint at line 437 in PostProcessorRegistrationDelegate$BeanPostProcessorChecker))	
	owns: ConcurrentHashMap<K,V>  (id=42)	
	PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization(Object, String) line: 437	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 438	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1789	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 600	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 522	
	DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 326	
	0x000000013e1f97e8.getObject() line: not available	
	DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 234	
	DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 324	
	DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: 200	
	ConstructorResolver.instantiateUsingFactoryMethod(String, RootBeanDefinition, Object[]) line: 409	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).instantiateUsingFactoryMethod(String, RootBeanDefinition, Object[]) line: 1335	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBeanInstance(String, RootBeanDefinition, Object[]) line: 1165	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 562	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 522	
	DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 326	
	0x000000013e1f97e8.getObject() line: not available	
	DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 234	
	DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 324	
	DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 205	
	AbstractAdvisorAutoProxyCreator$BeanFactoryAdvisorRetrievalHelperAdapter(BeanFactoryAdvisorRetrievalHelper).findAdvisorBeans() line: 91	
	InfrastructureAdvisorAutoProxyCreator(AbstractAdvisorAutoProxyCreator).findCandidateAdvisors() line: 111	
	InfrastructureAdvisorAutoProxyCreator(AbstractAdvisorAutoProxyCreator).findEligibleAdvisors(Class<?>, String) line: 96	
	InfrastructureAdvisorAutoProxyCreator(AbstractAdvisorAutoProxyCreator).getAdvicesAndAdvisorsForBean(Class<?>, String, TargetSource) line: 78	
	InfrastructureAdvisorAutoProxyCreator(AbstractAutoProxyCreator).wrapIfNecessary(Object, String, Object) line: 368	
	InfrastructureAdvisorAutoProxyCreator(AbstractAutoProxyCreator).postProcessAfterInitialization(Object, String) line: 320	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyBeanPostProcessorsAfterInitialization(Object, String) line: 438	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).initializeBean(String, Object, RootBeanDefinition) line: 1789	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).doCreateBean(String, RootBeanDefinition, Object[]) line: 600	
	DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).createBean(String, RootBeanDefinition, Object[]) line: 522	
	DefaultListableBeanFactory(AbstractBeanFactory).lambda$doGetBean$0(String, RootBeanDefinition, Object[]) line: 326	
	0x000000013e1f97e8.getObject() line: not available	
	DefaultListableBeanFactory(DefaultSingletonBeanRegistry).getSingleton(String, ObjectFactory<?>) line: 234	
	DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 324	
	DefaultListableBeanFactory(AbstractBeanFactory).getBean(String, Class<T>) line: 205	
	PostProcessorRegistrationDelegate.registerBeanPostProcessors(ConfigurableListableBeanFactory, AbstractApplicationContext) line: 277	
	AnnotationConfigServletWebServerApplicationContext(AbstractApplicationContext).registerBeanPostProcessors(ConfigurableListableBeanFactory) line: 805	
	AnnotationConfigServletWebServerApplicationContext(AbstractApplicationContext).refresh() line: 608	
	AnnotationConfigServletWebServerApplicationContext(ServletWebServerApplicationContext).refresh() line: 146	
	SpringApplication.refresh(ConfigurableApplicationContext) line: 754	
	SpringApplication.refreshContext(ConfigurableApplicationContext) line: 456	
	SpringApplication.run(String...) line: 334	
	SpringApplication.run(Class<?>[], String[]) line: 1354	
	SpringApplication.run(Class<?>, String...) line: 1343	
	Application.main(String[]) line: 34	

It's finding eligible advisors that's causing the problem. This is happening through AbstractAutoProxyCreator.postProcessAfterInitialization(Object, String) that's called after healthEndpointGroupsBeanPostProcessor has been created and initialized. The warnings can be reduced by marking the dependencies of the sample's Advisor bean, authorizationManagerBeforeMethodInterception, as @Lazy:

@Bean
@Role(ROLE_INFRASTRUCTURE)
public Advisor authorizationManagerBeforeMethodInterception(@Lazy AuthorizationManager<MethodInvocation> authorizationManager,
                                                            @Lazy AuthorizationEventPublisher publisher) {
    AuthorizationManagerBeforeMethodInterceptor authorizationManagerBeforeMethodInterceptor =
        AuthorizationManagerBeforeMethodInterceptor.preAuthorize(authorizationManager);
    authorizationManagerBeforeMethodInterceptor.setAuthorizationEventPublisher(publisher);

    return authorizationManagerBeforeMethodInterceptor;
}

This reduces the warnings from five to two:

2024-07-10T10:05:55.107+01:00  WARN 3196 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'application.SecurityConfig.OAuthSecurityConfig' of type [org.example.testsb.Application$SecurityConfig$OAuthSecurityConfig$$SpringCGLIB$$0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.
2024-07-10T10:05:55.141+01:00  WARN 3196 --- [testSB3.3.1] [           main] trationDelegate$BeanPostProcessorChecker : Bean 'authorizationEventPublisher' of type [org.springframework.security.authorization.SpringAuthorizationEventPublisher] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [healthEndpointGroupsBeanPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.

Is it possible to detect the case where Advisor beans are involved and point people in that direction?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions