与 Spring 的集成测试:无法转换类型错误的值
我正在为我们的 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 是一个类(不是接口)
我有以下内容:
<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>
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?
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)
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经经历过几次这样的事了。 这意味着spring创建的代理没有实现正确的接口。
我建议您在注入器上放置一个断点并检查 $Proxy47 以确定它正在实现什么。
另外,如果该类 om.xyz.business.grounding.service.OdometerPdfStatement 实现了 2 个接口,我不确定 spring 如何决定在代理时使用哪个接口。 我怀疑它可能实现两个接口,并且正在另一个接口上创建代理。
I've had this a few times. It means that the proxy that spring created does not implement the correct inteface.
I suggest you put a break point on the injector and inspect that $Proxy47 to ascertain what it is implementing.
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.
看起来您需要将 cglib jar 添加到您的类路径中。 Cglib 确保 Spring 可以代理具体类,而不仅仅是接口。
It looks like you need to add the cglib jar to your classpath. Cglib insures that Spring can proxy concrete classes, not just interfaces.