Spring Batch @StepScope cannot generate CGLIB subclass

前端 未结 2 1034
野趣味
野趣味 2021-01-01 04:03

EDIT

I created a test project that replicates the issue. It can be found at https://github.com/tomverelst/test-batch.

First run the maven co

相关标签:
2条回答
  • 2021-01-01 04:21

    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>
    
    0 讨论(0)
  • 2021-01-01 04:32

    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)

    0 讨论(0)
提交回复
热议问题