Spring batch scope issue while using spring boot

前端 未结 6 1188
感动是毒
感动是毒 2020-11-30 05:13

I\'m having Standalone spring batch job. This works perfectly fine when in JUNIT

@RunWith(SpringJUnit4ClassRunner.class)
//@SpringApplicationConfiguration(cl         


        
6条回答
  •  北海茫月
    2020-11-30 05:35

    You can solve by 2 Ways:

    A.

    Use spring.main.allow-bean-definition-overriding=true in application.properties

    B.

    To solve spring boot batch scope issue and avoid the use of spring.main.allow-bean-definition-overriding=true:

    Solutions:

    Disable autoProxy of StepScope. To perform that use following code snippet as a reference:

    
          
    
    

    Now perform following Spring bean configuration:

    A.)

    To configure step scope via XML-Based configuration:

     
       
     
    

    B.)

    To configure step scope via Java-Based configuration:

    @StepScope
    @Component(value = "userPreferences")
    public class UserPreference {}
    

提交回复
热议问题