maven test class files are not getting loaded: NoClassDefFoundError
I am getting following error while running junit test file with maven:
Caused by:java.lang.NoClassDefFoundError:IllegalName:开发者_JS百科com/home/app/LoginDetailsTest
all my test class files are located at target\ test-classes and java class files are located at target\ classes directory.
since LoginDetailsTest located at target\ test-classes, it couldnot identify class files. how to solve this error?
spring xml file:
<bean id="loginDetails" class="com/home/app/LoginDetailsTest">
<property name="loginDetailsService" ref="loginService" />
</bean>
I am running junit test file through eclipse by right click and run as junit test.
<error message="Cannot find class [/com/home/app/LoginDetailsTest] for bean with name 'loginDetails' defined in class path resource [com/home/app/LoginDetails-ctx.xml]; nested exception is java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest" type="org.springframework.beans.factory.CannotLoadBeanClassException">org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [/com/home/app/LoginDetailsTest] for bean with name 'loginDetails' defined in class path resource [com/home/app/LoginDetails-ctx.xml]; nested exception is java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.home.app.LoginDetailsTest.testLoginDetails(LoginDetailsTest.java:27)
Caused by: java.lang.ClassNotFoundException: /com/home/app/LoginDetailsTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:257)
at org.springframework.bea
You have to give the class name this way in Spring : "com.home.app.LoginDetailsTest", not this way "com/home/app/LoginDetailsTest"
精彩评论