写测试代码的时候出现了java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.
代码如下:
package com.example.service;
import com.example.config.SpringConifg;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConifg.class)
public class UserServiceTest {
@Autowired
private UserService userService;
@Test
public void testSelect()
{
System.out.println(userService.select());
}
}
最后发现是spring-webmvc
和 spring-test
的依赖版本不一致导致的。