未加载maven测试类文件:NoClassDefFoundError

时间:2011-08-28 11:33:28

标签: spring maven

使用maven运行junit测试文件时出现以下错误:

  

致   由:java.lang.NoClassDefFoundError:IllegalName:COM /家/应用程序/ LoginDetailsTest

我的所有测试类文件都位于target \ test-classes ,java类文件位于target \ classes 目录中。

由于LoginDetailsTest位于target \ test-classes ,因此无法识别类文件。如何解决这个错误?

spring xml文件:

<bean id="loginDetails" class="com/home/app/LoginDetailsTest">
    <property name="loginDetailsService" ref="loginService" />
</bean>

我通过右键单击eclipse运行junit测试文件并运行为junit test。

<error message="Cannot find class [/com/home/app/LoginDetailsTest] for bean with name &apos;loginDetails&apos; 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 &apos;loginDetails&apos; 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.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(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

1 个答案:

答案 0 :(得分:1)

你必须在Spring中以这种方式给出类名:“com.home.app.LoginDetailsTest”,而不是这样“com / home / app / LoginDetailsTest”