目录

1、更新project和重新引入

2、本地仓库检查

3、查看pom的依赖


SpringBoot包本地编译时有测试代码,报错为程序包org.springframework.test.context不存在,但是从从IDEA中点进类里可以看到对应的包。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestAction {

}

1、更新project和重新引入


maven update ,这个看了下 idea里面并没有,Eclipse才有,
Reimport All maven projects

2、本地仓库检查


进入本地仓库目录,查看仓库里面也有对应版本号的包,故删除之后重新引入。

3、查看pom的依赖

最终试了很多次之后还是没有解决问题,回归到最起点,虽然类是能点击进去看到对应的内容,但是究竟依赖有没有问题呢?

从pom文件查找依赖,发现划红线的两个包压根没引用进来。

  <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <version>2.3.4.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.2.9.RELEASE</version>
            <scope>test</scope>
        </dependency>

遂重新引入,编译成功。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐