Spring Boot入门-快速搭建web项目

Posted Java碎碎念

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot入门-快速搭建web项目相关的知识,希望对你有一定的参考价值。

Spring Boot 概述:

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

Spring Boot可以轻松创建独立的,生产级的基于Spring的应用程序,而你需要做的仅仅是run 这个项目。
Spring Boot 的设计是为了让你尽可能快的跑起来 Spring 应用程序并且尽可能减少你的配置文件。

Spring Boot特性:

  • 创建独立运行的Spring应用程序

  • 直接嵌入Tomcat,Jetty或Undertow(无需部署WAR文件)

  • 提供starter简化maven配置

  • 尽可能自动配置Spring和第三方库

  • 提供准生产的应用监控功能,例如指标,运行状况检查

  • 绝对没有代码生成,也不需要XML配置

  • Spring Boot快速搭建web项目

Spring Boot项目搭建

  1. 访问:https://start.spring.io/,如下图所示(spring boot版本2.1.2,依赖了web)填写相关的项目信息、依赖等,就会生成一个maven项目的压缩包,下载解压

技术图片spring官网截图

  1. 打开idea,找到file-->open-->选择项目的路径,找打pom文件-->以project 形式打开

    技术图片idea导入截图

     

    技术图片选择Open as Project截图
  2. 编写HelloController,放到包(com.example.helloSpringBoot.controller)下,HelloController代码如下:

package com.example.helloSpringBoot.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String HelloSpring (){
        System.out.println("hello spring boot");
        return "hello spring boot";
    }
}
  1. 点击运行按钮,查看运行结果,截图如下:

    技术图片运行按钮截图

     

    技术图片运行日志截图
  2. 项目启动成功后,浏览器输入 http://localhost:8080/hello 访问,看到下面成功截图后,说明项目搭建成功

技术图片浏览器访问截图


下面的是我的公众号二维码图片,欢迎关注,欢迎留言,一起学习,一起进步。

技术图片Java碎碎念公众号

 

以上是关于Spring Boot入门-快速搭建web项目的主要内容,如果未能解决你的问题,请参考以下文章

用Spring Boot零配置快速创建web项目

Spring-Boot快速搭建web项目详细总结

使用IDEA搭建Spring Boot入门项目

Spring boot 基础web入门搭建

(Spring Boot框架)快速入门

入门SpringBoot-Spring Initializer快速创建Spring Boot项目