具有作用域bean的Spring批处理和AllowBeanDefinitionOverriding = false

时间:2016-02-19 05:37:34

标签: java spring spring-batch spring-aop

我想使用范围化的弹簧批量bean

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

和AllowBeanDefinitionOverriding = false

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

如何避免使用Spring版本4.2.4.RELEASE

的BeanDefinitionStoreException
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)

或与Spring 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)

0 个答案:

没有答案