今天用JUNIT测试的时候,报了一个错误:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(TestContextManager.java:185)
at org.springframework.test.context.TestContextManager.
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
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)
采取了以下手段尝试解决:
1、查找slf4j相关jar有没有加入到classpath
发现已经加了:slf4j-log4j12-1.7.7.jar slf4j-api-1.7.7.jar log4j-1.2.17.jar
2、查看是否slf4j的包有无不同版本重复或者冲突
发现没有
3、那只能认为slf4j的jar包没在classpath中,没有被编译,但是classpath中确实是有啊。那咋办呢?
为了验证猜测是否正确,将(ps:开发工具是myeclipse)应用部署到了tomcat,然后打开部署目录,到该项目的lib目录,发现仅有两个jar文件。
回到我的项目,我的习惯是在系统的根目录建一个lib,然后把系统所需要用jar包都放进去,接着再加入到编译目录。采用这种方式,IDE偶尔会产生无法将LIB文件夹下的jar包部署到容器中。
接下去这个问题就好解决了,按标准的WEB项目结构,将jar包放入到指定的目录。问题解决