springboot出现SpringApplication无法导入包的问题

最简单的springboot入门配置,出现SpringApplication无法import包,maven下载jar失败

推荐方法三,可以先试试方法三

image

点开SpringApplication错误

image

1.

找到C:\Users\lenovo\.m2\repository\org\springframework\boot下面的spring-boot-autoconfigure,把他删除

项目右键—>Run As—>Maven clean

然后项目右键—>Maven—>Update Project..

项目右键—>Run As—>Maven install

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project springboot: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]

这是提示jdk环境不对

2.

image

配置jdk路径

image

选择jdk路径

image

选择jdk文件夹下的jre,并且是选到这个文件,而不是选择同级的jre

3.

更改pom文件,我的jdk是1.8的,所以这里指定跟本地一样的1.8版本

这里1.5.7.RELEASE的springboot是官方推荐的文件版本的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ma.springboot</groupId>
    <artifactId>springboot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>springboot</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

最后导入junit包,apptest错误也消失

项目右键—>Run As—>Maven clean

然后项目右键—>Maven—>Update Project..

项目右键—>Run As—>Maven install

猜你喜欢

转载自blog.csdn.net/Mint6/article/details/78068046