首页 > 编程 > Java > 正文

Spring Boot 工程的创建和运行(图文)

2019-11-26 10:19:11
字体:
来源:转载
供稿:网友

概述

还没玩过Spring Boot,现在越来越多的公司在用了,不得不学习了。本篇是Spring Boot的开篇,简单介绍一下如何创建一个Spring Boot项目和运行起来。

环境准备

1、JDK 1.8
2、IDEA

创建Spring Boot的工程

new一个project

这里写图片描述

选择Spring Initializr

这里写图片描述

选择使用JDK1.8后,点击Next。

填写Group和Artifact

这里写图片描述

这里我写的是

Group: com.springboot
Artifact:study

同时选用Maven来构建程序。选择完后点击Next。

选择Spring Boot的版本和组件

这里写图片描述

为了演示方便,目前就先勾选Web组件即可。选完后点击Next。

修改工程名称

这里写图片描述

本文使用的工程名称是

spring_boot_study

修改完后,点击finish按钮。

运行Spring Boot程序

经过上面的步骤后,Spring Boot为我们默认生成了一个启动类,叫StudyApplication,我们就基于这个来编写一个Hello程序。

package com.springboot;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestControllerpublic class StudyApplication {  @RequestMapping("/hello")  public String hello() {    return "hello,Spring Boot";  }  public static void main(String[] args) {    SpringApplication.run(StudyApplication.class, args);  }}

直接在IDEA中运行这个main方法,就可以启动这个Spring Boot程序了。访问路径如下:

http://localhost:8080/hello

输出结果如下

hello,Spring Boot

可以从启动日志中,看到默认端口号是8080。
这里写图片描述

到此,一个简单的Spring Boot的程序就构建成功了。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表