Java 与Spring的集成测试:无法转换类型错误的值

Java 与Spring的集成测试:无法转换类型错误的值,java,spring,junit,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:/

我正在为我们的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:
OdoMeterDFStatement是一个类(不是接口)

我有以下资料:

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


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

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

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

我建议您在喷油器上设置一个断点,并检查$Proxy47,以确定它正在实现什么


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

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

我建议您在喷油器上设置一个断点,并检查$Proxy47,以确定它正在实现什么



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

您是否在任何地方使用某种AOP?“$Proxy47”听起来很可疑Boyd4715:是的,我们确实有AOP——这对如何从ant运行单元/整数测试有影响吗?您是否在任何地方使用某种AOP?“$Proxy47”听起来很可疑Boyd4715:是的,我们有AOP——这对如何从ant运行单元/整数测试有影响吗?我的类路径中有以下内容:cglib-nodep-2.1_3.jar。请注意,我能够在IDE中运行测试脚本,没有任何问题。使用RAD7.0.X作为IDE。实际上,
[$Proxy47]
显示cglib可用且正在运行;只是它搞错了代理的确切内容。@如果该类名表示使用了经典的Java代理;cglib代理类将包括EnhancedByCGLIB(),换句话说,Spring看到了正在实现的接口,并决定经典的Java代理可以很好地适应?哦,很高兴。@alf-不,Spring只代理了接口,因为CGLib不可用。我的类路径中有以下内容:CGLib-nodep-2.1_3.jar。请注意,我能够在IDE中运行测试脚本,没有任何问题。使用RAD7.0.X作为IDE。实际上,
[$Proxy47]
显示cglib可用且正在运行;只是它搞错了代理的确切内容。@如果该类名表示使用了经典的Java代理;cglib代理类将包括EnhancedByCGLIB(),换句话说,Spring看到了正在实现的接口,并决定经典的Java代理可以很好地适应?哦,很高兴。@alf-不,因为CGLib不可用,所以Spring只代理了接口。我们在JUnit 4.6中使用Spring 2.0.x,知道有什么问题吗?我应该把它放在JUnit3.8上吗?另外,我正在做的集成测试是一个后端应用程序-带有EJB的Ear-非常感谢您的回答!只是碰到了同样的问题;删除接口是有帮助的。我们正在使用Spring2.0.x和JUnit4.6。知道这方面的问题吗?我应该把它放在JUnit3.8上吗?另外,我正在做的集成测试是一个后端应用程序-带有EJB的Ear-非常感谢您的回答!只是碰到了同样的问题;删除接口有帮助。