日常遇到的问题
在测试的时候遇到打上@SpringBootTest不生效,并且也使得@Autowired注入失效。
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration,
you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
原因是:在测试类上打上@SpringBootTest的注解,不能自动导入,所以不起效。
解决:在测试类上手动导入即可
@SpringBootTest(classes = PublisherApplication.class)
public class SpringAmqpTest {}