Spring batch with scoped beans and AllowBeanDefinitionOverriding=false

China☆狼群 提交于 2019-12-12 16:30:36

问题


I want to use scoped spring batch beans

 <bean id="processor"
 class="com.example.Processor"  
 p:type="#{jobParameters['type']}"
 scope="step"/>

and AllowBeanDefinitionOverriding = false

GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.setAllowBeanDefinitionOverriding(false);
context.load("myResource.xml", "otherResource.xml");
context.refresh();

How to avoid BeanDefinitionStoreException with Spring version 4.2.4.RELEASE

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'xxx' defined in BeanDefinition defined in class path resource [yyyy]: Cannot register bean definition [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in BeanDefinition defined in class path resource [yyyy]] for bean 'xxx': There is already [Generic bean: class [xxxProcessor]; scope=step; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=false; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [yyyy]] 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:678)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)

or the same with Spring version 3.1.4.RELEASE

at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:638)
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.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:670)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)

来源:https://stackoverflow.com/questions/35498037/spring-batch-with-scoped-beans-and-allowbeandefinitionoverriding-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!