search
HomeJavajavaTutorialBuild a simple spring boot project example

Build a simple spring boot project example

May 18, 2018 pm 02:10 PM
bootspringgetting Started

Introduction

  • Spring Boot is a new framework provided by the Pivotal team. It is designed to simplify the initial construction and development process of new Spring applications. The framework uses an ad hoc approach to configuration, eliminating the need for developers to define boilerplate configurations. In this way, Spring Boot strives to become a leader in the booming field of rapid application development.

  • In previous spring projects, we would face a lot of tedious configurations, and basically use them with a lot of copy and paste. Spring Boot allows us to easily and quickly build Spring Web applications without excessive configuration. It can be used out of the box without code generation or XML configuration, allowing us to quickly use the spring framework.

Start

Version: java 1.8.0_51 & spring boot 1.5.4

1. Build a simple spring boot project

The generator SPRING INITIALIZR provided on the official website here is used to create a simple spring boot project.

1. Visit http://start.spring.io

Spring INITIALIZR.png

Options: Project (maven) Language (java) SpringBoot version (1.5.4)
Group fills in the group name, Artifact fills in the module name, Dependencies on the right side can select the corresponding dependencies, because we want to build a web project, so we can add web dependencies.
Click Generate Project to generate the download project.

2. Import the downloaded maven project into the IDE and run it

Extract the downloaded project and import it into the IDE (IntelliJ IDEA is used here)
As follows:

spring boot.png

Directly run the main method of DemoApplication.java.
Screenshot of successful operation:

Build a simple spring boot project example

You can see that the process ID of the project is: 25642, and you can view the detailed information through java's jconsole tool.
You can see that the startup port of the project is 8080 (spring boot default port, which can be modified in application.properties)

Build a simple spring boot project example

2. pom.xml Explain

Open the pom.xml file and view the configuration information

Inherit the parent module. The spring-boot-starter-parent module contains automatic configuration, logs and YAML (reference:), so Building spring projects becomes easy.

 <!-- 继承 spring boot 父包-->
<parent>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-parent</artifactid>
    <version>1.5.4.RELEASE</version>
    <relativepath></relativepath> <!-- lookup parent from repository -->
</parent>

pom.xml relies on the spring-boot-starter-web module, including Tomcat and spring-webmvc (reference:). There is no need to specify the version because the parent module already has the default configuration. If needed Specified versions can be added.

<!-- 构建web项目模块 包括了Tomcat和spring-webmvc -->
<!-- spring-boot-starter-web 默认依赖了tomcat的starter 所以使得项目可以直接运行而不需要部署到tomcat中-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

pom.xml depends on the spring-boot-starter-test test module, including JUnit, Hamcrest, Mockito

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
In spring-boot, module dependencies They are all done in the starter format and named in the spring-boot-starter- format, with indicating the specific module. The spring-boot ecosystem provides a wealth of starters for developers to use (reference:)
This modular dependency simplifies a large number of dependency configurations. Using the starter dependency method, you can depend on the corresponding dependent packages into the project together, unlike traditional Spring which requires separate dependent packages.
For example, the web module in spring-boot needs to rely on web service packages such as org.springframework spring-web in traditional Spring configuration. In spring-boot, it only needs to rely on spring-boot-starter- The web can depend on the corresponding packages, greatly simplifying the configuration.

Supplementary

The above explains that the spring-boot project can be built directly from http://start.spring.io
The following explains directly in IntelliJ IDEA Build the spring-boot project

1. Open IDEA and create a new project

new project.png

2. Select Spring Initializr and fill in https:// in Choose Initializr Service URL. start.spring.io, click Next

spring i.png

##3. Fill in Group Artifact and other relevant information, click Next

Build a simple spring boot project example

4. Select the modules you need to depend on and click Next

Build a simple spring boot project example

The above is the detailed content of Build a simple spring boot project example. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list?How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to safely convert Java objects to arrays?How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How do I convert names to numbers to implement sorting and maintain consistency in groups?How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the default run configuration list of SpringBoot projects in Idea for team members to share?How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),