2012-08-29 91 views
1

我在我的pom.xml中有下面的配置。測試用例未按預期運行?

<dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.5.2</version> 
     </dependency> 

但是當我運行測試用例它給了我下面的錯誤:

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.debug(SLF4JLocationAwareLog.java:133) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:106) 
    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.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:34) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestMethodReference.<init>(JUnit4TestMethodReference.java:25) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:54) 
    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

可能使用錯誤的版本。 –

回答

0

你可能需要包括以下內容的依賴,以及:如果你想使用SLF4J在Spring

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.5.2</version> 
</dependency> 
0

那麼我建議你使用下面的依賴關係:

<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>${slf4j-version}</version> 
</dependency> 

<!-- 
    This forces the Java commons logging that is used as part of Spring 
    to use slf4j 
--> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>jcl-over-slf4j</artifactId> 
    <version>${slf4j-version}</version> 
    <scope>runtime</scope> 
</dependency> 

<!-- 
    Use log4j as the slf4j implementation 
--> 
<dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    <version>${slf4j-version}</version> 
    <scope>runtime</scope> 
</dependency> 

<!-- 
    You will also need log4j itself. 
    It includes a lot of cruft, so exclude the parts you don't want. 
--> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.15</version> 
    <exclusions> 
    <exclusion> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>javax.jms</groupId> 
     <artifactId>jms</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>com.sun.jdmk</groupId> 
     <artifactId>jmxtools</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>com.sun.jmx</groupId> 
     <artifactId>jmxri</artifactId> 
    </exclusion> 
    </exclusions> 
    <scope>runtime</scope> 
</dependency> 

我使用版本1.6.6的slf4j,但只要版本在每個依賴關係中保持一致,則無關緊要。

+0

添加不要忘記從你的Spring依賴項中排除'commons-logging'。 –