如何创建一个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)
上一篇 2022年8月31日 上午11:00
下一篇 2022年8月31日 上午11:00


相关推荐

  • flowable流程详解

    flowable流程详解flowable图例解释请假流程bpmn20.xml文件请假流程示例图例解释开始事件:图中用细线圆圈来表示,是流程实例的开始点箭头:表示节点之间的流转指向。用户任务:在图中用左上角有人的圆角矩形表示,这些是需要用户来操作的节点。图中有两个,第一个表示需要经理进行审批来同意或拒绝,第二个表示用户来确认销假。排它网关:用叉形符号填充的菱形表示,从该图中出来的箭头往往有多个,但只有一个满足条件,流程会沿着满足条件的方向流转。自动化任务:左上角有齿轮形状的的圆角矩形,表示自动执行的节点。图中

    2022年5月11日
    318
  • 定位?

    定位?

    2021年6月18日
    98
  • 自适应横向宽屏幻灯片代码

    自适应横向宽屏幻灯片代码工作需要利用 jsilde实现页面幻灯片效果,利用此插件实现起来比较简单,具体步骤如下:1.head区域引入jquery.jslides.css样式表文件。 2.引入JS文件jquery-1.8.0.min.js和jquery.jslides.js 3.在你的网页中加入注释区的代码,注意图片路径。 4.为了更宽的屏幕显示较好的效果,建议图片宽度大于等于1

    2022年7月14日
    17
  • maven的热部署

    maven的热部署在tomcat中配置用户权限,即添加管理员帐号 在根目录/conf/tomcat-users.xml 里添加下面的代码 &lt;rolerolename="manager-gui"/&gt;&lt;rolerolename="manager-script"/&gt;&lt;userusername="admin"password="admin"roles="mana

    2022年5月18日
    41
  • mysql自增主键设置

    mysql自增主键设置mysql 自增主键设置在数据库应用中 经常希望在每次插入新纪录时 系统自动生成字段的主键值 可以通过为表主键添加 AUTO INCREMENT 关键字来实现 默认情况下 在 MYSQL 中 AUTO INCREMENT 的初始值是 1 每新增一条记录 字段值自动加 1 一个表只能有一个字段属用 AUTO INCREMENT 约束 且该字段必须为主键的一部分 AUTO INCREMENT 约束的字段可以是任何整数类型 TINTINT SMALLINT INT BIGINT 等 设置表的属性值自动增加的语法规则如下 字段名

    2025年8月6日
    4
  • Python画图之浪漫樱花

    Python画图之浪漫樱花importturtleasTimportrandomimporttime#画樱花的躯干(60,t)defTree(branch,t):time.sleep(0.0005)ifbranch>3:if8<=branch<=12:ifrandom.randint(0,2)…

    2022年6月10日
    35

发表回复

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

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