Spring Batch @StepScope cannot generate CGLIB subclass

老子叫甜甜 提交于 2019-12-03 21:18:20

I can not provide you an actual answer (yet), but I've debugged the example you have provided and this is happening:

  • @Configuration definition reader sees @StepScope annotation which is annotated with @Scope(value = "step", proxyMode = ScopedProxyMode.TARGET_CLASS)
  • CGLIB subclass of reader is created and registered as reader while the original bean is registered as scopedTarget.reader.
  • StepScope kicks in and post-processes step scoped beans. It detects the CGLIB extended reader definition and tries to create proxy for that => ERROR.

There are two proxying mechanisms in conflict. There is something really weird going on and it seems to me that this can never work. Will try to search through Spring JIRA.


UPDATE

Found solution - you need to disable auto-proxying for the step scope:

<bean class="org.springframework.batch.core.scope.StepScope">
    <property name="autoProxy" value="false" />
</bean>

Easly remove <bean class="org.springframework.batch.core.scope.StepScope" /> from your configuration file; you don't need to add it explicit because is defined in batch namespace (as described in official documentation of Step scope)

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