IDEA各版本下载链接:https://www.jetbrains.com/zh-cn/idea/download/other.html
本教程使用的是2021.03.03版本IDEA
添加依赖才可以创建 springboot 项目
依赖是付费的,需要找到免费的历史版本,从本地安装
Spring Boot Helper下载好后自动变成此插件
本教程使用的是JDK-17
下载链接:https://www.oracle.com/java/technologies/downloads/#jdk17-windows
下载后发现文件夹里面没有jre文件 (其实并不影响)
解决方案:
文件夹路径中直接输入”cmd“即可
命令:bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre
注意:Path路径中的 %JAVA_HOME%\bin 要放在第一个
本教程使用的是3.6.0版本Maven
maven的 settings.xml 中,直接覆盖即可
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\software\apache-maven-3.6.0\repository</localRepository>
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
</settings>
-DarchetypeCatalog=internal
这一步很重要:
-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true
选择Maven项目,否则出现:Error: Request failed with status code 500
这里可以选择Spring Boot 的版本,本教程实际使用的版本为 1.5.3.RELEASE
这里手动添加了最后一个依赖
完整的 pom.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>springbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springbootdemo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
HelloWorld.java :
package com.test.springbootdemo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("hello")
public class HelloWorld {
@RequestMapping("helloworld")
public String helloWorld() {
return "Hello World";
}
}
application.properties :
#启动端口
server.port=8088
解决方案:
lombok更新到最新版本
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<optional>true</optional>
</dependency>
解决方案:
导入相应jar包:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
SpringbootdemoApplicationTests:
package com.test.springbootdemo;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringbootdemoApplicationTests {
@Test
void contextLoads() {
}
}
java.lang.IllegalStateException: Cannot load configuration class: com.test.springbootdemo.SpringbootdemoApplication
参考:
环境变量配置(同时安装多个JDK) ? 评论也可参考
IDEA中已配置阿里镜像,但maven无法下载jar包的问题