Java 无法转换[com.sun.proxy.$Proxy32 ScopedObject]类型的值
我使用的是SpringBatch,下面是配置Java 无法转换[com.sun.proxy.$Proxy32 ScopedObject]类型的值,java,spring,spring-batch,Java,Spring,Spring Batch,我使用的是SpringBatch,下面是配置 <beans:bean id="symfonyJob" class="com.st.symfony.Symfony" p:dir="${symfony.dir}" p:consolePath="${symfony.console.path}" p:strUtil-ref="strUtil" p:logFilePath="${batch.log.file.path}.#{jobParameters[batch_id]}" scop
<beans:bean id="symfonyJob" class="com.st.symfony.Symfony"
p:dir="${symfony.dir}" p:consolePath="${symfony.console.path}"
p:strUtil-ref="strUtil" p:logFilePath="${batch.log.file.path}.#{jobParameters[batch_id]}" scope="step"/>
<beans:bean id="importExchangesItemWriter"
class="com.st.batch.foundation.ImportExchangesItemWriter"
p:symfony-ref="symfonyJob" p:replyTimeout="${import.exchanges.reply.timeout}" scope="step"/>
<beans:bean id="importExchangesFileItemReader"
class="org.springframework.batch.item.file.MultiThreadedFlatFileItemReader"
p:resource="file:${spring.tmp.batch.dir}/#{jobParameters[batch_id]}/exchanges.txt"
p:lineMapper-ref="stLineMapper" p:startAt="#{stepExecutionContext['startAt']}"
p:maxItemCount="#{stepExecutionContext['itemsCount']}" scope="step" />
<step id="importExchangesStep">
<tasklet transaction-manager="transactionManager">
<chunk reader="importExchangesFileItemReader" writer="importExchangesItemWriter"
commit-interval="${import.exchanges.commit.interval}" />
</tasklet>
</step>
<job id="importExchangesJob" restartable="true">
<step id="importExchangesStep.master">
<partition partitioner="importExchangesPartitioner"
handler="importExchangesPartitionHandler" />
</step>
</job>
尽管reader有作用域步骤,但它仍在工作,但当我将其添加到writer时,我就开始出现此错误。您需要为SymfonyJobBean公开
,因为标准代理创建会公开接口,而不是具体的类(如您所需,因为ImportExchangesItemWriter.setSymfony()
accept-当然-一个com.st.symfony.symfony
参数,而不是一个接口)。您可以通过谷歌搜索“aop proxytargetclass”获得有关代理创建机制的更多信息。我在一个稍微不同的场景中看到了这个错误: 我没有遵循HibernateDAOBean的正确模式,它需要方法接口,并将接口类型作为属性而不是DAO实现类传递给服务层Springbean applicationContext.xml
<bean id="myEntityDAO" class="com.me.etc.MyEntityDAOImpl" parent="hibernateDAO"/>
<bean id="myEntityService class="com.me.etc.MyEntityServiceImpl">
<property name="myEntityDAO" ref="myEntityDAO" />
</bean>
Spring希望传入接口,而不是导致“无法转换类型的值”的实现类文件错误。您有没有找到解决方案?我的解决方案是在接收类中使用接口,而不是具体类。请参阅@Jim Ford answerCreating interface并将属性类型更改为interface type。谢谢
<bean id="myEntityDAO" class="com.me.etc.MyEntityDAOImpl" parent="hibernateDAO"/>
<bean id="myEntityService class="com.me.etc.MyEntityServiceImpl">
<property name="myEntityDAO" ref="myEntityDAO" />
</bean>
class MyEntityServiceImpl extends MyEntityService {
.
.
.
// I got the error when I had this property of class MyEntityDAOImpl
private MyEntityDAOInterface myEntityDAO;
// changed the setter as well to match
@Required
public setMyEntityDAO(MyEntityDAOInterface myEntityDAO) {
this.myEntityDAO = myEntityDAO;
}
.
.
.
}