如何创建一个SpringBoot项目?(详细的图文教程)

如何创建一个SpringBoot项目?(详细的图文教程)SpringBoot简介SpringBoot官网地址:https://www.spring.io官网介绍:SpringBootmakesiteasytocreatestand-alone,production-gradeSpring-basedApplicationsthatyoucanrun.WetakeanopinionatedviewoftheSpringplatformandthird-partylibraries,sothaty

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

如何创建一个SpringBoot项目?

SpringBoot 官网

官网介绍:

Spring Boot makes it easy to create stand-alone, production-grade Spring-based Applications that you can run. We take an opinionated view of the Spring platform and third-party libraries, so that you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
You can use Spring Boot to create Java applications that can be started by using java -jar or more traditional war deployments. We also provide a command line tool that runs “spring scripts”.Our primary goals are:

  • Provide a radically faster and widely accessible getting-started experience for all Spring development.
  • Be opinionated out of the box but get out of the way quickly as requirements start to diverge from the defaults.
  • Provide a range of non-functional features that are common to large classes of projects (such as embedded servers, security, metrics,
    health checks, and externalized configuration).
  • Absolutely no code generation and no requirement for XML configuration.

简单理解为:

  • 更广泛的、迅速的 Spring 开发体验
  • 一系列开箱即用的 starter
  • 一系列非功能性的自动化配置(无法实现业务配置)
  • 没有xml配置文件生成
SpringBoot 工程创建:(三种方式)

1. 在线创建

  • 官方推荐方式: spring initializr
    • 选择开发语言,版本号,填写项目名,打包方式,指定 Java 版本等,点击 GENERATE,网站自动生成并下载 SpringBoot 项目
    • 解压下载的文件,用开发工具打开即可。

在这里插入图片描述

2. 通过 IDE 创建(IntelliJ IDEA)

在这里插入图片描述

  • 点击 Spring Initializr , 选择 JDK 版本 ,选择 Default ,点击 Next;

在这里插入图片描述

  • 填写Group 和 Artifact 信息,选择对应的开发语言,打包方式,Java 版本等 ,点击 Next;

在这里插入图片描述

  • 选择 Web 依赖 和 Spring Boot 版本号,点击 Next;

在这里插入图片描述

  • 选择项目的保存位置,点击 FINISH

在这里插入图片描述

  • 点击 Enable Auto-Import 导入依赖

在这里插入图片描述

  • 至此创建完成

在这里插入图片描述

3. 通过改造 Maven 工程创建

  • 在IDEA 界面,依次点击 File -> New -> Project;

在这里插入图片描述

  • 选择 Maven 和 JDK 版本,点击 Next; (此处不选择 Maven 模板)

在这里插入图片描述

  • 修改项目名和指定项目地址

在这里插入图片描述

  1. 创建POM文件: Creating the POM
    在pom.xml 文件中引入:
	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>
  1. 添加 SpringBoot 依赖: Adding Classpath Dependencies
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

此时的pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>SpringBootDemo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>
  1. 编写启动类:Writing the Code
  • 新建包(包名最好为项目名),并创建启动类;

在这里插入图片描述

  • 编写启动类:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration //开启自动配置
public class SpringBootApplication { 
   

    @RequestMapping("/")
    String home() { 
   
        return "Hello World!";
    }

    public static void main(String[] args) { 
   
        SpringApplication.run(SpringBootApplication.class, args);
    }
}

在这里插入图片描述

检测是否创建成功?

  • 启动 main() 方法

在这里插入图片描述

  • 访问 localhost:8080
    在这里插入图片描述
    至此 SpringBoot 创建成功!

ps:如有错误,欢迎批评指正,谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/183872.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Charles抓包显示乱码解决方法

    Charles抓包显示乱码解决方法

    2021年6月16日
    136
  • C# 匿名方法和拉姆达表达式「建议收藏」

    C# 匿名方法和拉姆达表达式「建议收藏」“`“`代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace拉姆拉表达式{///

    ///C#匿名方法和拉姆达表达

    2022年9月15日
    0
  • 2021DIY电脑配置入门篇(包含各cpu显卡天梯图对比)

    2021DIY电脑配置入门篇(包含各cpu显卡天梯图对比)前言:我本来以为一篇文章可以把电脑配置讲清楚的,但是发现电脑比我想象的要复杂,所以可能分了几篇来写如何查看自己的电脑配置最简单的右键桌面此电脑->点击属性下载个电脑管家等电脑助手软件也可以查看详细配置如何DIY自己的第一台电脑篇幅有限,这里我只详细分析一台电脑的核心配置(CPU、主板、显卡),外加内存定好预算对于电脑来说,预算是最重要的!没有预算,一切都是空谈。没预算默认外星人Area51M(价格在2万左右),现在电脑往往充当一种娱乐需求,相对来说比较次要,因此大多数人配电脑.

    2022年7月12日
    28
  • linux的vi命令详解_useradd命令详解

    linux的vi命令详解_useradd命令详解最近vi用的多,很多技巧不知道,备注一份,vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令。由于对Unix及Linux系统的任何版本,vi编辑器是完全相同的,因此您可以在其他任何介绍vi的地方进一步了解它。Vi也是Linux中最基本的文本编辑器,学会它后,您将在Linux的世界里畅行无阻。

    2022年9月22日
    0
  • python抛出异常和捕获异常_在try块中可以抛出异常吗

    python抛出异常和捕获异常_在try块中可以抛出异常吗PythonLearnPython抛出异常【1】程序运行过程中Python解释器遇到一个错误会停止程序的运行并且提示一些错误信息这个就是异常程序停止并且提示错误信息的动作叫做抛出异常抛出异常原因 主动捕获异常可以增加健壮性抛出异常的种类AssertionError,断言失败抛出异常;AttributeError,找不到属性抛出异常;ValueError,…

    2022年10月18日
    0
  • sql 时间转换问题 from_unixtime() UNIX_TIMESTAMP()「建议收藏」

    sql 时间转换问题 from_unixtime() UNIX_TIMESTAMP()「建议收藏」from_unixtime()是MySQL里的时间函数  date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串  后面的 ‘%Y%m%d’ 主要是将返回值格式化  例如:  mysql>SELECT FROM_UNIXTIME( 1249488000, ‘%Y%m%d’ )    ->20071120  mysql>SELE

    2025年6月30日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号