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

Duplicate JobScope beans created when loading XML based bean definitions with SpringApplication.setSources #4533

Open
anthochristen opened this issue Jan 19, 2024 · 1 comment
Labels
has: minimal-example Bug reports that provide a minimal complete reproducible example in: core type: bug

Comments

@anthochristen
Copy link

This is similar to #3936 with the distinction that this happen for JobScope beans.

Coming to the issue, the below spring boot 2 setup (see reproducer below) throws a BeanDefinitionOverrideException during startup only when configuring the beans using XML based bean definitions with the SpringApplication.setSources method same works while using Java based bean definition or while using the same XML in `@ImportResource.

Reproducer:
https://github.com/anthochristen/testing-spring-batch

Error:

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'scopedTarget.reader', defined in BeanDefinition defined in org.example.Main, could not be registered. A bean with that name has already been defined in org.example.Main and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true


Process finished with exit code 1

What I see

I see that the step scope bean poxy scopedTarget.reader is registered twice in the Bean definition registry once while Spring does loads the Main config class and second again when the JobScope post processor (PP) is invoked and it doesn't recognise the existing scoped proxy created during load of the first source, causing this error.

While using Java based configs the JobScope Bean PP has the auto proxy flag set to false (in ScopeConfiguration class), so it doesn't proxy the bean. And while using ImportResource way the XML definition is only parsed in refreshContext after the ScopeConfiguration is initialised so it works as expected.

@anthochristen anthochristen added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Jan 19, 2024
@fmbenhassine fmbenhassine added in: core has: minimal-example Bug reports that provide a minimal complete reproducible example and removed status: waiting-for-triage Issues that we did not analyse yet labels Jan 22, 2024
@anthochristen
Copy link
Author

Also in the CoreNamespaceUtils condition to check for existing scope post processor beans I see that BeanDefinition.getBeanClassName returns the class name of the bean only in XML definitions.
When we define a custom stepScope or jobScope bean using java configuration the BeanDefinition.getBeanClassName returns the class name where the bean definition is done os it ignores those beans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: minimal-example Bug reports that provide a minimal complete reproducible example in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants