java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
我在看《Spring实战》,里头有源代码,我试着跑Test,不过出了问题,来求教下,测试代码如下:
package com.springinaction.springidol;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("spring-idol.xml")
public class AnnotationConfigTest {
@Autowired
@Qualifier("eddie")
private Instrumentalist eddie;
@Autowired
@Qualifier("guitar")
private Instrument guitar;
@Test
public void shouldWireWithAutowire() {
assertNotNull(eddie.getInstrument());
assertEquals(guitar, eddie.getInstrument());
}
}
抛出的异常是
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
我上网查了下,网上都是说JUnit4现在的版本将这个类移除了,要加新包,所以我就加了maven的依赖:
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
但是还是一直报同一个错误
另外,我在下下来的maven-repository里头是能够找到SelfDescribing.class文件。我也尝试使用了各种版本的JUnit4。
请大家教教我吧,谢谢!