Skip to content

Not possible to use step scope when allowBeanDefinitionOverriding is false [BATCH-2552] #1050

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

Closed
spring-projects-issues opened this issue Oct 27, 2016 · 6 comments
Labels
has: minimal-example Bug reports that provide a minimal complete reproducible example has: votes Issues that have votes in: core status: superseded Issues that are superseded by other issues type: bug

Comments

@spring-projects-issues
Copy link
Collaborator

Marcin Kiełbasiński opened BATCH-2552 and commented

Step scope is implemented as bean factory post processor and it registers proxy under the same name as target.

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'TItemSupersessionReaderQueryProvider' defined in BeanDefinition defined in URL [file:/C:/workspaces/o
m/OM/om-app/target/jee-module-classes/META-INF/springbeans/custom/core/om-batch-beans.xml]: Cannot register bean definition [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; sc
ope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nul
l; defined in BeanDefinition defined in URL [file:/C:/workspaces/om/OM/om-app/target/jee-module-classes/META-INF/springbeans/custom/core/om-batch-beans.xml]] for bean 'TItemSupersessionReaderQueryProv
ider': There is already [Generic bean: class [com.xxx.om.batch.TItemSupersessionReaderQueryProvider]; scope=step; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandida
te=false; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [file:/C:/workspaces/om/OM/om-app/target/jee-module-classes/META-INF/
springbeans/custom/core/om-batch-beans.xml]] bound.
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:825)
	at org.springframework.batch.core.scope.BatchScopeSupport.createScopedProxy(BatchScopeSupport.java:159)
	at org.springframework.batch.core.scope.BatchScopeSupport.postProcessBeanFactory(BatchScopeSupport.java:130)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:674)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519)
...

Affects: 3.0.7

@mederel
Copy link

mederel commented Jan 31, 2020

Hi,

affected by this problem too. Have to enable bean overrides to be able to use spring-batch :-(

I have written this simple maven project that allows to reproduce the issue:
spring-batch-issue-reproducer.tar.gz

The issue seems to have been reported 4 years ago in 2016. I am not against working on fix, but I have a hard time understanding what can be done in the BatchScopeSupport and what is the use of each line. I would need help.

mederel added a commit to mederel/spring-batch that referenced this issue Jan 31, 2020
@mederel
Copy link

mederel commented Jan 31, 2020

I tried to do a contribution with a fix... But I am having a hard time reproducing the issue with a unit test:

https://github.com/spring-projects/spring-batch/compare/4.2.x...mederel:bugfix/BATCH-2552-BeanDefinitionStoreException-with-StepScope?expand=1

The unit test I have modified raises a NoUniqueBeanDefinitionException, not a BeanDefinitionOverrideException...

@matrunich
Copy link

Hi all.
Unfortunately - have the same issue. No any suggestions have not helped

Have app with several xml files with different batch job.
Previously we used WebSphere - now we are migrating on Spring Boot 2.

@mederel
Copy link

mederel commented Feb 6, 2020

in definitive migrated successfully by using the @EnableBatchProcessing annotation, but with the modular = true option.

It allows to define a BatchConfigurer object that allowed to inject the customized beans (notably the PlatformTransactionManager).

Maybe that could be an option for you too?

BTW Thanks for the help in Gitter.

@matrunich
Copy link

matrunich commented Feb 6, 2020

I think current issue is:

https://docs.spring.io/spring-batch/docs/current/reference/html/step.html#step-scope

  • Using a scope of Step is required in order to use late binding, because the bean cannot actually be instantiated until the Step starts, to allow the attributes to be found. Because it is not part of the Spring container by default, the scope must be added explicitly, by using the batch namespace or by including a bean definition explicitly for the StepScope, or by using the @EnableBatchProcessing annotation. Use only one of those methods. The following example uses the batch namespace:
  • And according to spring-batch-3.0.xsd
    <xsd:annotation> <xsd:documentation><![CDATA[ Defines the configuration elements for Spring Batch Core. ]]></xsd:documentation> </xsd:annotation>

Sooo. In our case we have

  1. batch in namespace
  2. bean with the step
  3. @ImportResours

Have not checked yet but. Bean factory tries to declare beans by @ImportResours
Then batch:xxx declares beans by it self.

Maybe that could be an option for you too?
@mederel Thanks for advice !

@mederel Does it work with allowBeanDefinitionOverriding =false ?

@fmbenhassine fmbenhassine added the has: minimal-example Bug reports that provide a minimal complete reproducible example label Mar 12, 2021
@fmbenhassine fmbenhassine added has: votes Issues that have votes and removed status: waiting-for-triage Issues that we did not analyse yet labels Jun 30, 2022
@fmbenhassine fmbenhassine added this to the 5.0.0 milestone Jun 30, 2022
@fmbenhassine fmbenhassine modified the milestones: 5.0.0, 5.0.0-M6 Aug 31, 2022
@fmbenhassine
Copy link
Contributor

This should be resolved with #3942 . If anyone has the same issue with v5, please add a comment here and we will dig deeper.

@fmbenhassine fmbenhassine closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
@fmbenhassine fmbenhassine added the status: superseded Issues that are superseded by other issues label Sep 20, 2022
@fmbenhassine fmbenhassine removed this from the 5.0.0-M6 milestone Sep 20, 2022
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 has: votes Issues that have votes in: core status: superseded Issues that are superseded by other issues type: bug
Projects
None yet
Development

No branches or pull requests

4 participants