SPRingBoot是一个开源的快速开发框架,便利开发人员快速开发java web应用,目前在业界应用普遍,是开发人员必学的神器。
SpringBoot官网地址:https://spring.io/projects/spring-boot,上面有详细的项目介绍。目前最新的版本是3.0.2

下面我们就一路来进修下,若何搭建SpringBoot项目,并实现简单的web挪用。
开发东西我们选择的是更流行的IDEA,下载地址如下:https://www.jetbrains.com/idea/

1.起首我们新建一个项目,翻开IDEA,选择File->New->Project,翻开项目新建窗口。

2.我们新建一个空项目JAVA项目,选择java,JDK选择当地安拆的版本,我当地安拆的是JDK1.8,选择Next,到下一个页面间接点Next。


3.ProjectName按照情况本身设置,我那里输入的是springboot,ProjectLocation设置当地项目途径,点Finish,完成项目标创建。

4.IDEA接纳了项目---模块---包的三层办理体例,我们创建完项目后,接下来创建模块。在IDEA中选择File->Project Structure,翻开项目构造页面。

5.选择Modules,点“+”号,选择New Module添加新的模块。


6.因为我们要创建SpringBoot项目,选择Spring Initializr,在右侧展示的Server URL是创建SpringBoot项目所需设置装备摆设的官方地址,模块途径选择在项目途径下面,如许便于办理。
保证理东西选择Maven,JDK按照现实情况选择安拆的版本,留意Project SDK的版本要与Java中指定的版本同一起来。
打包体例选择jar,Springboot会把tomcat打包进jar包中,可间接启动jar包,利用便利。

7.SpringBoot目前最新的版本是3.0.2,但是SpringBoot3是没法在JDK1.8下运行的,所以那里我选择了2.7.8那个版本。若是安拆的JDK版本大于或等于17,能够选择SpringBoot3。
下面的依赖是Spring官方针对差别的应用场景做好的设置装备摆设,SpringBoot的便当和快速开发的特征就表现在那里,选择了响应的场景,各类需要的jar包以及婚配的版本,springboot都帮你做好了,你只需要专注于营业逻辑的开发就好。
本次是要做java web开发,选择Web下的Spring Web。

8.模块创建好之后,能够看到项目目次下已有hello模块,能够用右侧的Maven刷新按钮,导入需要的依赖包。

9.到目前为行,SpringBoot项目就搭建好了,接下来我们看下SpringBoot的目次构造。
src是源码目次,java源码目次中以Application结尾的文件是SpringBoot的启动类,是SpringBoot项目标施行入口。
resources下的application.proPErties文件是SpringBoot的设置装备摆设文件,最简情况下不需要做任何设置装备摆设。

10.下面我创建一个简单的控造器测试下SpringBoot的功用。
在源码目次中创建控造器Test

11.在控造器中做好相关的注解设置装备摆设,创建一个响应前端恳求的办法,返回一个字符串。

12.启动SpringBoot项目,在启动类上点右键,选择Run。

13.在控造台能够看到,Springboot项目已经启动,内嵌的Tomcat也启动起来了,在8080端口监听。

14.在阅读器中输入拜候地址:http://localhost:8080/test/getstring
看到Test控造器做出了预期的响应,一个SpringBoot项目就如许运行起来了,是不是很简单?[浅笑]

总结:
SpringBoot项目设置装备摆设简单,几步操做就构建了一个能供给web办事的工程,没用过的抓紧尝尝吧。
发表评论