Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了java – Spring-Batch代理类不能转换为Class?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个春季批量@Job定义.但是在运行它时(在tomcat中),由于com.sun.proxy,我得到了一个ClassCastException.$Proxy.

为什么会出现这种情况?以下摘录可能有什么问题?

@service
public class Jobservice {
    @Autowired
    private JobLauncher launcher;

    public void run() {
        Job job = jobRegistry.getJob("jobname");
        launcher.run(job,params); //line 59
    }
}


@Configuration
@EnableBatchProcessing(modular = truE)
public class JobConfig {
    @Bean
    @JobScope
    public MultiresourceItemReader<>(); ...="" return="" itemreader;="" }="" @bean="" public="" jobscope="" jobscope()="" {="" return="" new="" jobscope();="" }="" }="">

结果:

java.lang.ClassCastException: com.sun.proxy.$Proxy135 cAnnot be cast to org.springframework.batch.item.file.MultiresourceItemReader
    at org.springframework.batch.item.file.MultiresourceItemReader$$FastClassBySpringcglib$$ad846cb.invoke(cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.cglibAopProxy$@L_767_5@methodInvocation.invokeJoinpoint(cglibAopProxy.java:708) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.support.DelegaTingIntroductionInterceptor.doproceed(DelegaTingIntroductionInterceptor.java:133) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.support.DelegaTingIntroductionInterceptor.invoke(DelegaTingIntroductionInterceptor.java:121) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.cglibAopProxy$DynamicAdvisedInterceptor.intercept(cglibAopProxy.java:644) ~[spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.batch.item.file.MultiresourceItemReader$$EnhancerBySpringcglib$$3a188c22.close(figuration.Annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.1.RELEASE.jar:3.0.1.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) [spring-aop-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at com.sun.proxy.$Proxy52.run(UnkNown sourcE) [?:?]
    at my.Jobservice.run(JobExecutor.java:59)
最佳答案
如果您不需要读者的具体类型,则返回ItemReader< t="">来自reader()函数.
@JobScope认使用cglib代理代理目标类.

大佬总结

以上是大佬教程为你收集整理的java – Spring-Batch代理类不能转换为Class?全部内容,希望文章能够帮你解决java – Spring-Batch代理类不能转换为Class?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。