spring boot Test @Autowired 失败
·
最近在做测试发现
spring boot Test @Autowired 失败经过查找发现 @Test默认是不允许注入的,需要做一些操作
1.要想@Autowired注入成功需要做一些操作
- 1.导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 2.测试类的
包名和源码的包名要一致 - 3.在启动类上添加注解
@RunWith(SpringRunner.class)
@SpringBootTest
- 4.启动成功
更多推荐
所有评论(0)