本文主要是介绍快速构建spirng-boot项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
快速构建spirng-boot项目
- https://start.spring.io/方式
- 打开浏览器,输入地址:https://start.spring.io/
- 选择Switch to the full version,这个选项让我们可以有更多的关于项目技术的选择
- 选择项目需要的技术,让spring-boot帮助我们集成,包括数据库、接口等主流技术都可以选择,不限于我展示的几类
- 选择好技术,点击完成,下载集成的项目
- IDEA开发工具(如果你还使用Eclipse/MyEclipse请赶快学习使用这个工具,超级好用,并且已经开始流行起来)
注意:IDEA工具只有14以后的版本才支持spring-boot
第一次,下面步骤需要时间比较久,有可能连接超时等问题,多尝试几次,毕竟国内网络连接国外的网站。(如果出现连接等问题,请参考这个博客:https://blog.csdn.net/sinat_32366329/article/details/82750982)
下面填写项目的相关信息
下面选择项目的相关技术,选择好后spring-boot会自动帮助我们集成,不需要我们单独的去配置
最后填写项目名称
- Spring Boot CLI方式
插件下载地址:https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/
我下载的版本地址:https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.0.5.RELEASE/spring-boot-cli-2.0.5.RELEASE-bin.zip
配置环境变量,解压出来后重命名
计算机(右键) -> 属性 -> 高级系统设置 -> 环境变量
编辑Path系统参数,将spring-boot-cli的环境变量添加上去,注意分号;%SPRING_BOOT_CLI_HOME%\bin
打开控制台,检查配置结果是否成功,输入spring --version
输入一下命令生成项目:spring init --build=maven --java-version=1.8 --dependencies=web --p
ackaging=jar --boot-version=2.0.5.RELEASE --groupId=com.rabbit --artifactId=my-spring-boot
出现一下情况表示成功。
–build:表示项目构建工具maven,也可以选择gradle
— java-version:表示JDK版本
–dependencies=web:表示依赖web插件
–packaging:表示打包程序方式
–boot-version:选择 spring boot的版本
–groupId:maven的groupId
–artifactId:maven的artifactId
自己搜索一下看保存到哪里,默认是在当前用户的文件夹目录下
打开查看目录结构,自己解压然后导入到开发工具中即可,如果是eclipse需要安装STS插件支持spring-boot,如果是IDEA需要14版本以上才支持spring-boot
- Maven手工构建
至于如果创建一个空的Maven项目,这里不多介绍,百度就有大把。主要介绍如何构建是的项目支持Spring-boot
添加Spring Boot的父级依赖,这样当前项目就是Spring Boot项目了。spring-boot-starter-parent是一个特殊的starter,它用来提供相关的Maven默认依赖。提供的依赖可以去:C:\Users\vip\.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.0.5.RELEASE\spring-boot-starter-parent-2.0.5.RELEASE.pom中查看(具体每个人的Maven地址不一样,请根据自己的具体情况查看)。
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.5.RELEASE</version><relativePath /></parent> |
添加对Web的支持start.pom,这样就添加了Web的依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> |
添加Spring Boot的编译插件
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build> |
基础测试编写代码
@RestController@SpringBootApplicationpublic class MyApplication {@RequestMapping("/")public String index() {return "Hello Spring Boot";}} |
启动类
public class Main {public static void main(String[] args) {SpringApplication.run(MyApplication.class);}} |
访问结果
这篇关于快速构建spirng-boot项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!