今天写代码,在test的类中@Autowired注入要测试的@Component类,但发现一运行就会报空指针异常java.lang.NullPointException,但发现使用new的方法的时候可以注入这个@Component类,但是要调用这个@Component中注入的其他的类时也会报空指针异常,在网上查了很多,比如说在idea软件里test的目录是在src下,但是都没有解决,直到搜到一位道友的博客,讲述了,这个是由于test类的,没有使用@SpringBootTest注解,可以先建一个TmallApplicationTests 类
package com.eastcom.aijud.fm.statistic.steam;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringRu