在我的项目中,我混合了Spring Javaconfig和XML配置,由于Spring具有方便的批处理命名空间,我只使用它。在xml配置中,我指的是@JobScope监听器,如此
<step abstract="true" id="hist">
<listeners>
<listener ref="histListener"/>
</listeners>
</step>
此侦听器定义为Javaconfig @Bean
@Bean
@JobScope
public HistListener histListener(@Value("#{jobParameters[inputFilePath]}") String inputFilePath) {
return new HistListener(inputFilePath);
}
问题是,当解析XML时,它期望在没有参数的情况下调用代理bean histListener 构造函数,即使它需要作业注入的 inputFilePath 参数范围@Value注释。
java.lang.ClassCastException: $Proxy216 cannot be cast to org.springframework.batch.core.listener.StepExecutionListenerSupport
at org.springframework.batch.core.listener.StepExecutionListenerSupport$$FastClassBySpringCGLIB$$c521b3f5.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at sdc.service.injection.springbatch.listener.HistListener$$EnhancerBySpringCGLIB$$24a84ea5.beforeStep(<generated>)
at org.springframework.batch.core.listener.CompositeStepExecutionListener.beforeStep(CompositeStepExecutionListener.java:77)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:194)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:386)
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at $Proxy86.run(Unknown Source)
我已经能够毫无问题地将@Bean转换为其XML等价物,但似乎在这种情况下,XML和JavaConfig不相处。有没有人找到解决方案?