spring批处理Hadoop因org.springframework.beans.factory.BeanNotOfRequiredTypeException

时间:2016-01-04 22:26:18

标签: spring hadoop mapreduce spring-batch

我有一个弹出批处理作业,触发了一个hadoop作业。请参阅下面的我的工作配置。当我启动工作时,我得到以下异常......

配置:

<hdp:job id="mr-my-job" 
        input-path="/data/input/"
        output-path="/data/output/"
        jar-by-class="org.test.Main" 
        mapper="org.test.Test1$Map"
        combiner="org.test.Test1$Combiner"
        reducer="org.test.Test1$ReduceFromCombiner"
        number-reducers="7"
        scope="step" />

例外:

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'mr-my-job' must be of type [org.apache.hadoop.mapreduce.Job], but was actually of type [$Proxy5]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:375)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.data.hadoop.mapreduce.JobExecutor.findJobs(JobExecutor.java:254)
        at org.springframework.data.hadoop.mapreduce.JobExecutor.startJobs(JobExecutor.java:166)
        at org.springframework.data.hadoop.batch.mapreduce.JobTasklet.execute(JobTasklet.java:90)
        at org.springframework.data.hadoop.batch.mapreduce.JobTasklet$$FastClassBySpringCGLIB$$4805a065.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 org.springframework.data.hadoop.batch.mapreduce.JobTasklet$$EnhancerBySpringCGLIB$$3be21557.execute(<generated>)
        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.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.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
        at $Proxy2.execute(Unknown Source)
        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
        at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)

我将CGLIB 3.1添加到classpath并添加     我的XML中<bean class="org.springframework.batch.core.scope.StepScope" p:proxyTargetClass="true" />但仍然遇到同样的错误。

我调试并发现在将org.springframework.aop.framework.JdkDynamicAopProxy@b57ceeff类型的bean转换为org.springframework.aop.framework.JdkDynamicAopProxy@b57ceeff时,在JobExecutor类的下一行抛出异常。我认为来自CGLIB的自动代理没有在这里应用,因为它仍在使用JDK代理。

JobExecutor类:

for (String name : jobNames) {
    js.add(beanFactory.getBean(name, Job.class));
}

AbstractBeanFactory类

return getTypeConverter().convertIfNecessary(bean, requiredType);

请建议。

1 个答案:

答案 0 :(得分:0)

感谢Luca Basso Ricci。 删除范围=&#34;步骤&#34;来自&#34; my-mr-job&#34;工作