使用Spring进行集成测试:无法转换类型错误的值

时间:2022-09-26 16:59:01

I am in the process of developing Integration Test scripts for our spring application. When I run the test from ant I am getting the following error message: Any ideal as why?

我正在为spring应用程序开发集成测试脚本。当我从蚂蚁运行测试时,我收到以下错误消息:任何理想为什么?

Testcase:

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 is a class (not an interface)

OdometerPDFStatement是一个类(不是接口)

I have the following:

我有以下内容:

    <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>

2 个解决方案

#1


I've had this a few times. It means that the proxy that spring created does not implement the correct inteface.

我已经有过几次了。这意味着spring创建的代理没有实现正确的接口。

I suggest you put a break point on the injector and inspect that $Proxy47 to ascertain what it is implementing.

我建议你在注射器上设置一个断点并检查$ Proxy47以确定它正在实现什么。

Also if that class om.xyz.business.grounding.service.OdometerPdfStatement implements 2 interfaces I'm not sure how spring decides which one to use when proxying. I suspect it might implement two interfaces and the proxy is being created on the other one.

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

#2


It looks like you need to add the cglib jar to your classpath. Cglib insures that Spring can proxy concrete classes, not just interfaces.

看起来您需要将cglib jar添加到类路径中。 Cglib确保Spring可以代理具体的类,而不仅仅是接口。

#1


I've had this a few times. It means that the proxy that spring created does not implement the correct inteface.

我已经有过几次了。这意味着spring创建的代理没有实现正确的接口。

I suggest you put a break point on the injector and inspect that $Proxy47 to ascertain what it is implementing.

我建议你在注射器上设置一个断点并检查$ Proxy47以确定它正在实现什么。

Also if that class om.xyz.business.grounding.service.OdometerPdfStatement implements 2 interfaces I'm not sure how spring decides which one to use when proxying. I suspect it might implement two interfaces and the proxy is being created on the other one.

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

#2


It looks like you need to add the cglib jar to your classpath. Cglib insures that Spring can proxy concrete classes, not just interfaces.

看起来您需要将cglib jar添加到类路径中。 Cglib确保Spring可以代理具体的类,而不仅仅是接口。