使用了autowired还是报错空指针异常说明就是包没有导入,springboot导包的操作在于启动application类,所以问题就在于没有单元测试时没有启动主类,
解决方法:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SaTokenDemoApplication.class)
加上如上的注解,@runwith只使用junit4运行单元测试,@springbootTest启动主类导入需要的包,如果还有疑问参考
解决SpringBoot单元测试@Autowired不生效问题
解决SpringBoot单元测试@Autowired不生效问题
- springboot Autowired nullpoint 单元springboot autowired nullpoint单元 transactional springboot autowired项目 springboot candidates autowired matching springframework springboot annotation autowired springboot autowired属性 invocationhandler springboot autowired springboot autowired resource 注解springboot autowired项目 注解templateengine springboot autowired nullpoint