springboot出現SpringApplication無法匯入包的問題
最簡單的springboot入門配置,出現SpringApplication無法import包,maven下載jar失敗
推薦方法三,可以先試試方法三
點開SpringApplication錯誤
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.
配置jdk路徑
選擇jdk路徑
選擇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