知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

    • Spring boot

      • Theory:Introduction to Spring boot
      • Theory:Getting started with Spring Boot
        • Generating a Spring Boot application
        • Running the application
      • Theory:Basic project structure
      • Theory:IoC container
      • Theory:Spring beans
  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • Spring boot
Jim
2022-07-14
目录

Theory:Getting started with Spring Boot

In this topic, you will learn how to create your first Spring Boot application. This application is quite simple and does nothing useful, but still, it will demonstrate the basic structure of any Spring Boot project.

# Generating a Spring Boot application

It is often hard to start a new project from scratch, especially for a beginner. You need to set up the basic structure, create configurations and manage all external dependencies. Fortunately, there is a special web site called Spring Initializr (opens new window) that can generate the basic Spring Boot project based on your wishes.

img

This site may look slightly different, but the general idea remains the same. There are several important options you need to specify before generating a project:

  • the build tool: Maven or Gradle
  • one of the possible JVM-based languages: Java (8, 11 or higher), Kotlin, Groovy
  • a version of Spring Boot framework (e.g, the last released version without SNAPSHOT, M and other suffixes).
  • metadata like group, artifact, description and package name
  • external dependencies (other frameworks and libraries)

If you are interested in the naming rules for Spring Boot versions and the meaning of the diverse suffixes, you can read this short article (opens new window).

In our example, we've chosen Gradle as the build tool and Java 11 as the language. You can choose a more recent version if you'd like. Our application is named demo.

By default, the packaging type for Spring Boot is Jar. It means that your application should be packed in a .jar file that contains all the required dependencies. This type of file is more simple to use than a .war file, which should be deployed on an external application server.

After you've chosen all the necessary settings and dependencies, just click Generate Project to get the project's archive. This archive contains the basic structure of a typical Spring Boot application without application logic; it is just a template, you need to write some logic there.

Note that another way to generate a Spring Boot application is to use an IDE like IntelliJ IDEA (opens new window).

# Running the application

Although the generated application is useless at the moment, it is a good template to start with.

Let's run it! First, unpack the application and then visit the project's directory. In our examples, we will use Gradle as it is a common build automation system.

First, we should build the application:

./gradlew build
1

It creates a .jar file using Gradle Wrapper and puts it in the build/libs/ directory. Gradle automatically downloads all the necessary dependencies while building.

When finished, it should print:

BUILD SUCCESSFUL in 1s
1

Now, it is time to run the program represented as a .jar file.

java -jar build/libs/*.jar
1

After running, this application just prints the Spring logo and several log lines that we skipped.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.4)
1
2
3
4
5
6
7

You may also build and start an application using a single line:

./gradlew build && java -jar build/libs/*.jar
1

Congratulations! You've just created and started your first application using the Spring Boot framework even without a single line of code, except for a pair of commands.

编辑 (opens new window)
#Framework#Spring boot
上次更新: 2022/10/12, 17:01:25
Theory:Introduction to Spring boot
Theory:Basic project structure

← Theory:Introduction to Spring boot Theory:Basic project structure→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式