java - 与Spring集成测试: Cannot convert value of type error

标签 java spring junit

我正在为我们的 Spring 应用程序开发集成测试脚本。当我从 ant 运行测试时,我收到以下错误消息:任何理想的原因?

测试用例:

testgetDefaultItemForStoreWithInvalidStoreId(com.xyz.business.admin.role.RoleUtilityUnitTest):  
Caused an ERROR Error creating bean with name 'groundingService' defined in URL 
[file:/C:/workspace/_EACE1_0_06/EB_Ace_Vob/Business/build/classess/businessContext.xml]: Error 
setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested 
PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.TypeMismatchException: 
Failed to convert property value of type [$Proxy47] to required type 
[com.xyz.business.grounding.service.OdometerPdfStatement] for property 'odometerPdfStatement'; nested exception 
is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy47] to required type 
[com.xyz.business.grounding.service.OdometerPdfStatement] for property 'odometerPdfStatement': no matching editors or 
conversion strategy found org.springframework.beans.factory.BeanCreationException: Error creating bean with 
name 'groundingService' defined in 
URL [file:/C:/workspace/_EACE1_0_06/EB_Ace_Vob/Business/build/classess/businessContext.xml]: Error 
setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested 
PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.TypeMismatchException: 
Failed to convert property value of type [$Proxy47] to required type 
[com.xyz.business.grounding.service.OdometerPdfStatement] for property 'odometerPdfStatement'; 
nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy47] to 
required type [com.xyz.business.grounding.service.OdometerPdfStatement] for property 'odometerPdfStatement': 
no matching editors or conversion strategy found Caused by: 
org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are: 
PropertyAccessException 1:

OdometerPDFStatement 是一个类(不是接口(interface))

我有以下内容:

    <bean id="odometerPdfStatement" class="com.xyz.business.grounding.service.OdometerPdfStatement"/>


<bean id="groundingService" class="com.xyz.business.grounding.service.GroundingServiceImpl">
    <property name="groundingInformationManager" ref="groundingInformationManager"/>
    <property name="codeManager" ref="codeManager"/>
    <property name="userManager" ref="userManager"/>
    <property name="configurator" ref="groundingConfigurator"/>
    <property name="velocityPropertyFilePath" value="velocity.properties"/>
    <property name="velocityTemplate" value="OdometerStatement.vm"/>
    <property name="odometerStatementXSLResourceFile" value="classpath:OdometerStatement2xsl-fo.xsl"/>
    <property name="imagePropertyFile" value="classpath:images.properties"/>
    <property name="odometerPdfStatement" ref="odometerPdfStatement"/>
    <property name="inspectionInformationManager" ref="inspectionInformationManager"/>
    <property name="saleEventManager" ref="saleEventManager"/>
    <property name="vehicleHistoryManager" ref="vehicleHistoryManager"/>
</bean>

最佳答案

我遇到过几次这样的情况。这意味着spring创建的代理没有实现正确的接口(interface)。

我建议您在注入(inject)器上放置一个断点并检查 $Proxy47 以确定它正在实现什么。

另外,如果 om.xyz.business.grounding.service.OdometerPdfStatement 类实现了 2 个接口(interface),我不确定 spring 如何决定在代理时使用哪个接口(interface)。我怀疑它可能实现两个接口(interface),并且正在另一个接口(interface)上创建代理。

关于java - 与Spring集成测试: Cannot convert value of type error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1132915/

相关文章:

java - NetBeans 对结果列表中的每个命中设置一个断点

java - Android 自定义 View 事件监听器在没有静态引用的情况下无法正常工作

java - Spring - 依赖注入(inject) - 哪个优先?

java - Spring CGlib 自动运行的奇怪行为?

java - 防止 junit 测试运行两次

ant - 使用依赖于环境变量的代码进行单元测试

java - java中测试文件 worker 的问题

java - 正则表达式将匹配行包装在井号内但不包含前导空格

java - foo(int, int) 比 foo(int...)

java - Spring自动类型转换不适用于字符串到日期