Fixes an issue with the contextDiagnostic being registered multiple times#25
Conversation
… only in parent context and prevent duplicate registration
|
| .getBeanFactory() | ||
| .registerSingleton("contextDiagnostic", completedDiagnostic); | ||
| LOG.debug("Context Diagnostic Completed: {}", completedDiagnostic); | ||
| if (event instanceof ContextRefreshedEvent contextEvent) { |
There was a problem hiding this comment.
looks like you should check parent before call ContextDiagnostic.started() in line 20
There was a problem hiding this comment.
The change @timbrueckner introduced in line 24 if(contextEvent.getApplicationContext().getParent() == null should do the trick now or do you mean there needs to be another parent check (@pavlickm)?
There was a problem hiding this comment.
i mean that you shouldn't start ContextDiagnostic in line 20 if parent is not null because otherway you may start many ContextDiagnostic , but complete ony one and finally results may be vary
There was a problem hiding this comment.
@timbrueckner @rieckpil
I implemented the same validation and initially did it the way you've described it, but later found it too complex to understand. Do you think it might make sense to wrap this validation in an "ensureContextNotExist" method or something similar to make the code easier to read? What do you think?
There was a problem hiding this comment.
I will integrate it as is, to fix the current issue of the duplicate bean.
There are still some cases where this diagnostic isn't working properly and still needs some additional work.
…t context (#25) Co-authored-by: Tim Brückner <[email protected]>



This pull request fixes the issue which caused the
contextDiagnosticbean to be registered twice if more than one ContextRefreshedEvent was handled inContextDiagnosticApplicationInitializer.This fix changes the registration to only react to the main (parent) application context.