junit测试报如下错误,且brow的404

问题描述

junit测试报如下错误,且brow的404

java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:161)
at org.springframework.context.annotation.ConfigurationClassUtils.isLiteConfigurationCandidate(ConfigurationClassUtils.java:106)
at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:88)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:255)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:225)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at cn.xuxu.login.service.testService.testUserService(testService.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 33 more

解决方案

Eclipse Junit测试报initializationError错误

解决方案二:

javax/servlet/ServletContext 所在的classpath配置对了吗?

解决方案三:

从这条日志:java.lang.NoClassDefFoundError: javax/servlet/ServletContext来看,是没有找到 javax/servlet/ServletContext,你可以在cn.xuxu.login.service.testService.testUserService(testService.java:18)打一个断点看看javax/servlet/ServletContext的路径

时间: 2024-10-27 06:02:25

junit测试报如下错误,且brow的404的相关文章

spring4.14+hibernate4.3整合,web运行正常,junit测试报错;

问题描述 spring4.14+hibernate4.3整合,web运行正常,junit测试报错: 之前web启动的时候也报这个错误,然后在web.xml里面加了这个filter,就好了. 可是现在用junit测试,没办法读取web.xml里面的配置,所以还报了这个错, 别问我为什么要junit测试,就是想知道 junit测试的时候这种情况怎么解决. 下面附代码 SpringOpenSessionInViewFilterorg.springframework.orm.hibernate4.sup

java spring junit-java junit测试报错找不到自己定义的xml文件 跪求各位高手帮忙解决一下

问题描述 java junit测试报错找不到自己定义的xml文件 跪求各位高手帮忙解决一下 eclipse下junit测试时遇到如下错误,错误内容如下: at jp.co.dgic.eclipse.jdt.internal.junit.runner.DJUnitRunner.main(DJUnitRunner.java:49) caused by:org.springframework.beans.factory. BeanDefinitionStoreException:IoException

junit测试报错,求大神救命,控制台输出如下,

问题描述 junit测试报错,求大神救命,控制台输出如下, 0 2015-07-09 09:04:52182 [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - #org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:316)# -

spring配置多数据源t junit测试报错

问题描述 spring配置多数据源t junit测试报错 Error creating bean with name 'seentao.workflow.engine.EngineTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: publi

studio-Android Studio中使用JUnit测试报错(ClassNotFoundException)

问题描述 Android Studio中使用JUnit测试报错(ClassNotFoundException) 在Android Studio中编写测试类public class MyAppTest extends ActivityInstrumentationTestCase2报错: Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter Caused by: java

spring/mybatis整合,junit测试报BeanCreationException

问题描述 昨天想整合下springmvc和mybatis,用junit写了个测试,测试过程中,mybatis的mapper无法注入,报BeanCreationException,相关信息大家看下,帮小弟解决下 1 错误堆栈信息    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.hft.dal.mapper.AccountMapperTest': Inject

junit 测试报错. 看了好久都没有解决..求解

问题描述 jar包也更换过了..就是没果,,求解...Class not found test.UserTestjava.lang.ClassNotFoundException: test.UserTestat java.net.URLClassLoader$1.run(URLClassLoader.java:200)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.fi

java junit4-JUnit测试报 No socket available 错误

问题描述 JUnit测试报 No socket available 错误 Eclipse进行JUnit测试时,总弹出 No socket available 窗口,导致测试不能进行. 解决方案 打开run configurations__让后勾选keep junit running after a test run when debugging 我的就是这样养解决的,希望对你有帮助! 解决方案二: Junit占用socket没有正常释放,在cmd中输入以下指令netsh winsock rese

图片-Java SSH整合框架.tomcat能正常跑,没问题.用junit测试却报配置错误.

问题描述 Java SSH整合框架.tomcat能正常跑,没问题.用junit测试却报配置错误. 配置如第一张图. 报错如下面两张. new ClassPathXmlApplicationContext("applicationContext.xml");junit初始化配置时出现的问题.最后导致beanFactory.containsBean("Sys_UserDao")为fasle 解决方案 不是已经说了没有引人hibernate属性文件啊, 解决方案二: 你的