Duplicate JobScope beans created when loading XML based bean definitions with SpringApplication.setSources #4533
Labels
has: minimal-example
Bug reports that provide a minimal complete reproducible example
in: core
type: bug
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 theSpringApplication.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:
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.
The text was updated successfully, but these errors were encountered: