user710818
user710818

Reputation: 24248

Is it possible to create junit test for injected methods in Spring?

I have abstract class:

public abstract ClassA {

 protected abstract void method1 {...}

Another class ClassB that implement method1.

XML:

bean id="BaseBean" class="ClassB"

bean id="WorkBean" class="ClassA"
lookup-method="method1" bean="BaseBean"

in test:

$RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:test.xml"
public class Test ....

@Autowired
private IClass classA;

When I try run this test I receive error:

java.lang.IllegalStateException: Failed to load ApplicationContext
....
Caused by: org.springframework.beans.factory.BeanCreationException: Error 
 creating   bean with name 'WorkBean' 
defined in class path resource [test.xml]: 
Instantiation of bean failed; nested exception is 
java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter
....
Caused by: java.lang.ClassNotFoundException: net.sf.cglib.proxy.CallbackFilter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

How can I fix?

Upvotes: 1

Views: 180

Answers (1)

JamesB
JamesB

Reputation: 7894

This is caused by the missing dependency library – cglib.

cglib at sourceforge

Upvotes: 2

Related Questions