-
Notifications
You must be signed in to change notification settings - Fork 26.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[master] Fix DubboConfigEarlyInitializationPostProcessor registered twice in Spring Framework #9397
Conversation
…eanPostProcess twice in PostProcessorRegistrationDelegate.registerBeanPostProcessors()(#9370)
if (beanFactory != null) { | ||
DubboConfigEarlyInitializationPostProcessor dceiPostProcessor = | ||
DubboConfigEarlyInitializationPostProcessor.getSingleton(beanFactory); | ||
// Register itself |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Register itself
change this comment
DubboConfigEarlyInitializationPostProcessor.getSingleton(beanFactory); | ||
// Register itself | ||
if (logger.isInfoEnabled()) { | ||
logger.info("BeanFactory is about to be initialized, trying to resolve the Dubbo Config Beans early " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this log message
if (beanFactory == null) { // try again if postProcessBeanDefinitionRegistry method does not effect. | ||
this.beanFactory = unwrap(beanFactory); | ||
initBeanFactory(); | ||
public static DubboConfigEarlyInitializationPostProcessor getSingleton(DefaultListableBeanFactory beanFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global instance of DubboConfigEarlyInitializationPostProcessor holds in DubboConfigEarlyRegistrationPostProcessor is better.
DubboConfigEarlyInitializationPostProcessor just a BeanPostProcessor , it should not care for how to create and be registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the DubboConfigEarlyInitializationPostProcessor can be changed to a inner class of DubboConfigEarlyRegistrationPostProcessor, it's managed by DubboConfigEarlyRegistrationPostProcessor. Then the relationship is more clear and reduce confusion.
The root cause of the incorrect beanProcessorCount is that DubboConfigEarlyInitializationPostProcessor has been registered twice, once by manual registration and once by Spring automatic registration. A more elegant solution is to register only once, and there is no problem with registering in BeanDefinitionRegistryPostProcessor. It is best to explain its role more accurately in the javadoc. |
Codecov Report
@@ Coverage Diff @@
## master #9397 +/- ##
============================================
- Coverage 60.85% 60.85% -0.01%
+ Complexity 448 447 -1
============================================
Files 1100 1100
Lines 44507 44509 +2
Branches 6473 6475 +2
============================================
Hits 27086 27086
+ Misses 14454 14452 -2
- Partials 2967 2971 +4
Continue to review full report at Codecov.
|
…tionPostProcessor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
private boolean hasRegisteredCommonAnnotationBeanPostProcessor() { | ||
for (BeanPostProcessor beanPostProcessor : beanFactory.getBeanPostProcessors()) { | ||
if (CommonAnnotationBeanPostProcessor.class.equals(beanPostProcessor.getClass())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to cache the result if has found CommonAnnotationBeanPostProcessor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to cache the result if has found CommonAnnotationBeanPostProcessor
Thanks for your reply. I can't cache the result all the time. Here is my reason:
There might be some BeanPostProcessors not instantiated before some Dubbo Config Bean instantiated (which will call this method),so the result of beanFactory.getBeanPostProcessors()
may not be the same when this method is called.
But, it can be cached after CommonAnnotationBeanPostProcessor instantiated, I will submit another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new PR #9414
What is the purpose of the change
fix #9370
Brief changelog
fix
DubboConfigEarlyInitializationPostProcessor
counted as BeanPostProcess twice inPostProcessorRegistrationDelegate.registerBeanPostProcessors()
Verifying this change
before
DubboConfigEarlyInitializationPostProcessor
inbeanFactory.getBeanPostProcessors()
andpostProcessorNames
The
beanProcessorTargetCount
is 17After registration the
beanFactory.getBeanPostProcessors()
should be 16after
No more
dubboConfigEarlyInitializationPostProcessor
inpostProcessorNames
The
beanProcessorTargetCount
is 16,After registration the
beanFactory.getBeanPostProcessors()
should be 16Checklist