Spring Test / JUnit problem - unable to load application context
Posted
by HDave
on Stack Overflow
See other posts from Stack Overflow
or by HDave
Published on 2010-05-19T13:41:07Z
Indexed on
2010/05/19
13:50 UTC
Read the original article
Hit count: 719
I am using Spring for the first time and must be doing something wrong. I have a project with several Bean implementations and now I am trying to create a test class with Spring Test and JUnit. I am trying to use Spring Test to inject a customized bean into the test class.
Here is my test-applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=".............">
<bean
id="MyUuidFactory"
class="com.myapp.UuidFactory"
scope="singleton" >
<property name="typeIdentifier" value="CLS" />
</bean>
<bean id="ThingyImplTest"
class="com.myapp.ThingyImplTest"
scope="singleton">
<property name="uuidFactory">
<idref local="MyUuidFactory" />
</property>
</bean>
</beans>
The injection of MyUuidFactory instance goes along with the following code from within the test class:
private UuidFactory uuidFactory;
public void setUuidFactory(UuidFactory uuidFactory) {
this.uuidFactory = uuidFactory;
}
However, when I go to run the test (in Eclipse or command line) I get the following error (stack trace omitted for brevity):
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyImplTest' defined in class path resource [test-applicationContext.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException:
Failed to convert property value of type 'java.lang.String' to required type 'com.myapp.UuidFactory' for property 'uuidFactory';
nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type [com.myapp.UuidFactory] for property 'uuidFactory':
no matching editors or conversion strategy found
Funny thing is, the Eclipse/Spring XML editor shows errors of I misspell any of the types or idrefs. If I leave the bean in, but comment out the dependency injection, everything work until I get a NullPointerException while running the test...which makes sense.
© Stack Overflow or respective owner