-
Notifications
You must be signed in to change notification settings - Fork 38.4k
When using Configuration annotation BeanDefinitionRegistryPostProcessor, the instance type of dependency injection is inconsistent with getBeanClassName in BeanDefinition #22990
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
Comments
Cannot enhance @configuration bean definition if its singleton instance has been created too early. Add the corresponding testcase. See spring-projects#22990.
I submit a PR to solve this issue. The PR follows the log that says In my opinion, I think we could enhance it even if it has been created. Maybe we should use the enhanced bean definition to create the new instance and override the old one. @jhoeller What is your opinion. If you agree with me, I would modify my PR which would create the new instance instead of following the log. |
@lgxbslgx @jhoeller This is not a good solution because it breaks the Spring bean singleton,because the beans created in advance have been invoked, if replacing the beans causes inconsistencies, I think it's only necessary to enhance the configuration beans that are not instantiated |
@lgxbslgx |
The code above maybe causes some problem. If |
@lgxbslgx Sorry, you're right. |
The fact that you have annotated it with How does your application behave if you annotate |
@sbrannen Yes, using @component would be the right performance. |
Thanks for the feedback, @brucelwl. Does that mean that we can close this issue as resolved from your end? |
I just think that if a developer accidentally uses |
Thanks for the additional input, @brucelwl. We'll consider whether it makes sense to provide additional diagnostic information for such use cases. |
When using Configuration annotation BeanDefinitionRegistryPostProcessor, the instance type of dependency injection is inconsistent with getBeanClassName in BeanDefinition. The code is as follows
The reasons are as follows:
The method enhanceConfigurationClasses in org.springframework.context.annotation.ConfigurationClassPostProcessor ,as long as beanDef is a full configuration, it will be added to configBeanDefs and then generated by cglib into the new class, resulting in updating the beanClassName in BeanDefinition. The code should be changed to the following
The text was updated successfully, but these errors were encountered: