1.SpringBoot测试Mybatis时注入mapper失败,报错
java.lang.NullPointerException
at com.test.UserMapperTest.testSelect(UserMapperTest.java:33)
解决方法
在测试类上加上注解
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest {...}
2.依然报错
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test...
解决方法
@SpringBootTest注解中指定启动类的字节码(MyApplication是自己定义的启动类)
@SpringBootTest(classes = MyApplication.class)