使用Junit Test时,@Autowired 注入出现空指针异常NullPointerException问题

1.添加maven依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>

2.测试类添加注解

@RunWith(SpringRunner.class)
@SpringBootTest

在这里插入图片描述

3.完成~~

おすすめ

転載: blog.csdn.net/weixin_42551369/article/details/119569550