Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected warn logs when using spring-integration in combination with webmvc #9103

Closed
epantke opened this issue Apr 26, 2024 · 2 comments
Closed

Comments

@epantke
Copy link

epantke commented Apr 26, 2024

In what version(s) of Spring Integration are you seeing this issue?
6.2.4

Describe the bug

When using spring-integration in combination with the xml elements from the webmvc xml namespace mvc:resources or mvc:annotation-driven the following warnings are shown:

26-Apr-2024 14:24:48.960 WARNING [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean '(inner bean)#597faa00' of type [org.springframework.web.servlet.resource.ResourceUrlProvider] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.
26-Apr-2024 14:24:48.965 WARNING [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean '(inner bean)#218f313c' of type [org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.
26-Apr-2024 14:24:49.086 WARNING [RMI TCP Connection(2)-127.0.0.1] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization Bean '(inner bean)#1ef73af4' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.

When using only one of the elements only a subset of these warning appear. With mvc:resources the warning for the ResourceUrlProvider and ResourceUrlProviderExposingInterceptor are logged. With mvc:annotation-driven the warning for the ConversionServiceExposingInterceptor is shown.

The spring framework (6.1.6) documentation states that having dependencies in BPPs is not recommended and might cause issues.

If you have beans wired into your BeanPostProcessor by using autowiring or @resource (which may
fall back to autowiring), Spring might access unexpected beans when searching for type-matching
dependency candidates and, therefore, make them ineligible for auto-proxying or other kinds of
bean post-processing
Spring Framework Docs

These log messages pollute the logs in any application using spring-integration this way; making it harder to identify the warnings that concern the application code and the beans defined within.

To Reproduce

  • Build the sample project in the attached zip.
  • Deploy the war in a matching web server (we used Tomcat 10.1.20)
  • Observe the warnings in the logs.
    warn-minimal-example.zip

Expected behavior

When using spring-integration in combination with spring-webmvc, no warnings are produced by the dependencies included.

Sample

warn-minimal-example.zip

@epantke epantke added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Apr 26, 2024
@artembilan
Copy link
Member

Thank you for the report.
I simply was able to reproduce it with our IntegrationGraphControllerTests.
It emits warning similar to yours:

2024-04-26 12:11:07,434 WARN [main] [org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker] - Bean '(inner bean)#39f5b723' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.

Because I indeed have there the mentioned <mvc:annotation-driven />.

Will investigate the reason and come up with the fix.

@artembilan artembilan added this to the 6.3.0 milestone Apr 26, 2024
@artembilan artembilan added in: http (EOL) for: backport-to-6.2.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Apr 26, 2024
@artembilan
Copy link
Member

The problem happens in the IntegrationRequestMappingHandlerMapping.setApplicationContext().
It uses its initApplicationContext(context); which does:

	protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) {
		mappedInterceptors.addAll(BeanFactoryUtils.beansOfTypeIncludingAncestors(
				obtainApplicationContext(), MappedInterceptor.class, true, false).values());
	}

And since this IntegrationRequestMappingHandlerMapping is a DestructionAwareBeanPostProcessor, it is created and initialized earlier for bean post-processing phase.
That one pulls those MappedInterceptor populated by the MVC XML configuration.
And that's exactly where it is not OK, because those beans are populated into an application context too early.

I think as a fix I'll extract that DestructionAwareBeanPostProcessor logic into separate component, so it won't affect the HandlerMapping initialization logic.

spring-builds pushed a commit that referenced this issue Apr 26, 2024
Fixes: #9103

The `IntegrationRequestMappingHandlerMapping` implements a `DestructionAwareBeanPostProcessor`
which causes an early bean initialization including interceptors loading from the application context:
```
2024-04-26 12:11:07,434 WARN [main] [org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker] - Bean '(inner bean)#39f5b723' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.
```

* Extract the `DestructionAwareBeanPostProcessor` logic from the `IntegrationRequestMappingHandlerMapping`
into separate `DynamicRequestMappingBeanPostProcessor` which does not cause eager beans initialization
* Verify with the `IntegrationGraphControllerTests` that the mentioned `not eligible for auto-proxying` warning is not emitted anymore

(cherry picked from commit 5d59271)
EddieChoCho pushed a commit to EddieChoCho/spring-integration that referenced this issue Jun 26, 2024
Fixes: spring-projects#9103

The `IntegrationRequestMappingHandlerMapping` implements a `DestructionAwareBeanPostProcessor`
which causes an early bean initialization including interceptors loading from the application context:
```
2024-04-26 12:11:07,434 WARN [main] [org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker] - Bean '(inner bean)#39f5b723' of type [org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor] 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 [integrationRequestMappingHandlerMapping]? Check the corresponding BeanPostProcessor declaration and its dependencies.
```

* Extract the `DestructionAwareBeanPostProcessor` logic from the `IntegrationRequestMappingHandlerMapping`
into separate `DynamicRequestMappingBeanPostProcessor` which does not cause eager beans initialization
* Verify with the `IntegrationGraphControllerTests` that the mentioned `not eligible for auto-proxying` warning is not emitted anymore

**Auto-cherry-pick to `6.2.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants