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

Warning log when using AnnotationEnhancer #3467

Closed
RuslanHryn opened this issue Aug 29, 2024 · 5 comments · Fixed by #3468
Closed

Warning log when using AnnotationEnhancer #3467

RuslanHryn opened this issue Aug 29, 2024 · 5 comments · Fixed by #3468

Comments

@RuslanHryn
Copy link

RuslanHryn commented Aug 29, 2024

In what version(s) of Spring for Apache Kafka are you seeing this issue?

in the latest version 3.2.3

Describe the bug

There is the following warning log when using AnnotationEnhancer at the start of the app:

trationDelegate$BeanPostProcessorChecker : Bean 'groupIdEnhancer' of type [org.example.springkafkaenhancerreproducer.EnhancerConfiguration$$Lambda/0x0000000800332650] 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 [org.springframework.kafka.config.internalKafkaListenerAnnotationProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.

As I know this warning means that BeanPostProcessor uses internalKafkaListenerAnnotationProcessor and Spring had to create internalKafkaListenerAnnotationProcessor before the BeanPostProcessor. That's why, internalKafkaListenerAnnotationProcessor can't be processed by the BeanPostProcessor.

Therefore, it should not cause any issues, but eliminating this warning would be nice.

To Reproduce

  1. Create AnnotationEnhancer as described here https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/kafkalistener-attrs.html
  2. Run the app on Spring Boot 3.2 or 3.3
  3. There is the following warning message in the logs:

trationDelegate$BeanPostProcessorChecker : Bean 'groupIdEnhancer' of type [org.example.springkafkaenhancerreproducer.EnhancerConfiguration$$Lambda/0x0000000800332650] 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 [org.springframework.kafka.config.internalKafkaListenerAnnotationProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies.

Expected behavior

No warning messages in the logs when using AnnotationEnhancer

Sample

I can provide if needed but it should be very easy to reproduce

@sobychacko
Copy link
Contributor

sobychacko commented Aug 29, 2024

@RuslanHryn Thanks for the report. We will look at this. Please go ahead and provide a sample as that would speed things up.

@RuslanHryn
Copy link
Author

@sobychacko thanks! forgot to mention that I'm able to reproduce this issue on Spring Boot 3.2 and 3.3

@artembilan
Copy link
Member

@RuslanHryn ,

I think you mean this doc since there is no mentioning of the AnnotationEnhancer in the testing chapter: https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/kafkalistener-attrs.html#page-title.

Do you have that your groupIdEnhancer bean definition declared as static like we suggest in the mentioned doc?

@RuslanHryn
Copy link
Author

RuslanHryn commented Aug 29, 2024

@artembilan Sorry, fixed the link in the description.

Do you have that your groupIdEnhancer bean definition declared as static like we suggest in the mentioned doc?

yes, it is static

@artembilan
Copy link
Member

Yeah... According to my testing that static still does not help.
There is another trick to skip that since it is really only for annotations and not supposed to be heavily dependent on some business logic.
Add @Role(BeanDefinition.ROLE_INFRASTRUCTURE) into that groupIdEnhancer bean definition.

@artembilan artembilan self-assigned this Aug 29, 2024
@artembilan artembilan added this to the 3.3.0-M3 milestone Aug 29, 2024
artembilan added a commit to artembilan/spring-kafka that referenced this issue Aug 29, 2024
…` for early BF access

Fixes: spring-projects#3467

The `KafkaListenerAnnotationBeanPostProcessor.afterPropertiesSet()` get access to `BeanFactory`
for other beans which causes a warning into logs like:
```
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
```

The rule of thumb is to not have any bean factory access from `BeanPostProcessor` initialization phase

* Fix `KafkaListenerAnnotationBeanPostProcessor` to `buildEnhancer()` i lazy manner.
Therefore remove an `afterPropertiesSet()` altogether

**Auto-cherry-pick to `3.2.x` & `3.1.x`**
spring-builds pushed a commit that referenced this issue Aug 29, 2024
…access (#3468)

Fixes: #3467

#3467

The `KafkaListenerAnnotationBeanPostProcessor.afterPropertiesSet()` gets access to `BeanFactory`
for other beans which causes a warning into logs like:
```
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
```

The rule of thumb is not to have any bean factory access from `BeanPostProcessor` initialization phase.

* Fix `KafkaListenerAnnotationBeanPostProcessor` to `buildEnhancer()` in lazy manner.
Therefore remove an `afterPropertiesSet()` altogether.

(cherry picked from commit 4a135a1)
spring-builds pushed a commit that referenced this issue Aug 29, 2024
…access (#3468)

Fixes: #3467

#3467

The `KafkaListenerAnnotationBeanPostProcessor.afterPropertiesSet()` gets access to `BeanFactory`
for other beans which causes a warning into logs like:
```
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
```

The rule of thumb is not to have any bean factory access from `BeanPostProcessor` initialization phase.

* Fix `KafkaListenerAnnotationBeanPostProcessor` to `buildEnhancer()` in lazy manner.
Therefore remove an `afterPropertiesSet()` altogether.

(cherry picked from commit 4a135a1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment