新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目本教程对新手小白友好

大家好,欢迎来到IT知识分享网。

新版idea(2023)创建spring boot3项目

⛰️个人主页:     蒾酒

🔥系列专栏《spring boot实战》


目录

前言

汉化教程

项目模板初始化

1.点击新建项目

2.配置初始化信息

3.初始依赖选择

配置Maven

1.打开maven设置

2.重写maven配置文件

3.选择你创建的配置文件

4.重启项目

spring boot配置并测试

1.修改配置文件后缀

2.启动项目

3.编写测试控制类

4.重启项目测试

代码获取

1.git方式获取

2.下载压缩包方式获取


前言

本教程对新手小白友好。如果你想直接获取代码或遇到问题可下载我提供的源码,在文章最后。

本教程较新

本文使用的工具以及搭建的springboot版本都是较新版本:

idea版本如下

新版idea(2023)创建spring boot3项目

spring boot 版本如下:

新版idea(2023)创建spring boot3项目

本教程使用的是汉化后的idea

汉化教程

下载一个汉化插件即可。

File->Settings

新版idea(2023)创建spring boot3项目

搜索:plugins

新版idea(2023)创建spring boot3项目

选择插件市场,搜索chinese安装

新版idea(2023)创建spring boot3项目

下载完毕重启即可。

新版idea(2023)创建spring boot3项目

或者:

新版idea(2023)创建spring boot3项目

项目模板初始化

1.点击新建项目

新版idea(2023)创建spring boot3项目

或者

新版idea(2023)创建spring boot3项目

2.配置初始化信息

新版idea(2023)创建spring boot3项目

这里提一嘴的是,在第7步,java版本选择上我的建议:java 8、Java 11、Java 17三个长期支持版

原因是开发商会对其提供长期支持服务,包括修复漏洞、解决问题和提供更新等。

spring boot 2x版本建议使用Java 8、Java 11

spring boot 3x版本最低要求 Java17

我创建的spring boot 3x版本所以选Java17 

最后第八步打包方式一定选择jar包。原因是,Spring Boot内置了Tomcat等Web服务器的支持,并提供了嵌入式容器的功能。这意味着你可以将整个应用程序以可执行的JAR文件的形式进行部署和运行,而无需外部的独立Web服务器。

点击下一步

新版idea(2023)创建spring boot3项目

如果你的idea版本较老可能没有我这个3x版本选择,你可以选择2x版本,然后回到上一步,jdk换成8或11。

注意:作者后续spring boot实战系列文章都会用spring boot3x,如果你想跟着博主实战教程建议保持跟博主一致。

3.初始依赖选择

选择几个常用初始依赖

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

选择好初始依赖点击创建,此时会去该spring官网下载初始化模板,稍等即可。

也可以不用idea自带的初始化,自行去spring官网初始化模板并下载:Spring Initializrhttps://start.spring.io/

初始化完成如图:

新版idea(2023)创建spring boot3项目

配置Maven

此时需要配置以下maven下载源为国内阿里云镜像,加速依赖下载

1.打开maven设置

展开主菜单->文件->设置->

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

输入maven搜索

新版idea(2023)创建spring boot3项目

2.重写maven配置文件

新版idea(2023)创建spring boot3项目

这里我不推荐通过maven目录的conf下去直接修改setting.xml方式去切换下载源以及java版本。

我们只需要提前准备好setting.xml即可。每次新建项目用到不同java版本只需要换不同配置文件即可。

新建一个txt ->打开文件粘贴阿里云镜像源配置内容 ->修改文件名为setting.xml

粘贴如下:

我的java版本是17

<?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"> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> </mirrors> <profiles> <profile> <id>JDK-17</id> <activation> <activeByDefault>true</activeByDefault> <jdk>17</jdk> </activation> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion> </properties> </profile> </profiles> </settings> 

如果你是Java11:

<?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"> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> </mirrors> <profiles> <profile> <id>JDK-11</id> <activation> <activeByDefault>true</activeByDefault> <jdk>11</jdk> </activation> <properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <maven.compiler.compilerVersion>11</maven.compiler.compilerVersion> </properties> </profile> </profiles> </settings> 

如果你是Java8:

<?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"> <pluginGroups> </pluginGroups> <proxies> </proxies> <servers> </servers> <mirrors> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> </mirrors> <profiles> <profile> <id>JDK-8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>8</jdk> </activation> <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <maven.compiler.compilerVersion>8</maven.compiler.compilerVersion> </properties> </profile> </profiles> </settings> 

粘贴完ctrl+s保存退出。

修改文件名为:setting.xml

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

3.选择你创建的配置文件

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

4.重启项目

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

此时依赖会马上下载好。

spring boot配置并测试

1.修改配置文件后缀

application.properties ->application.yml

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

此时你的配置文件啥都没写,但是可以直接运行项目,spring boot遵循约定大于配置理念,已经提供好了一组默认配置,你可以按需修改配置。

2.启动项目

这两处都能启动

新版idea(2023)创建spring boot3项目

新版idea(2023)创建spring boot3项目

3.编写测试控制类

新建controller目录下新建TestController类

新版idea(2023)创建spring boot3项目

import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/test") public class TestController { @GetMapping("/hello") public String test(){ return "hello world"; } }

4.重启项目测试

新版idea(2023)创建spring boot3项目

重启完成浏览器地址栏输入:localhost:8080/test/hello

新版idea(2023)创建spring boot3项目

成功输出返回响应。

5.简单配置项目端口以及项目名称

新版idea(2023)创建spring boot3项目

application.yml:

server: # 端口号 port: 8888 spring: application: # 应用名称 name: mijiu-app

代码获取

如果你参照该教程遇到问题,导致创建失败

可以自取我已经创建好的,项目根目录已经提供maven配置文件(阿里云镜像源,Java17)

蒾酒/springboot-demo (gitee.com)https://gitee.com/mi9688-wine/springboot-demo

1.git方式获取

代码地址:

https://gitee.com/mi9688-wine/springboot-demo

新版idea(2023)创建spring boot3项目

克隆后先编译一下在运行

新版idea(2023)创建spring boot3项目

2.下载压缩包方式获取

新版idea(2023)创建spring boot3项目

下载完解压用idea打开,编译,运行即可。

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/145229.html

(0)
上一篇 2025-04-21 14:15
下一篇 2025-04-21 14:20

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信