栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

概述

还没玩过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
@RestController
public 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的程序就构建成功了。

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/141754.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号