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
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:
Directly run the main method of DemoApplication.java.
Screenshot of successful operation:
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)
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
2. Select Spring Initializr and fill in https:// in Choose Initializr Service URL. start.spring.io, click Next
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!

Start Spring using IntelliJIDEAUltimate version...

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...

Java...

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...

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...

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

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 SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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
Easy-to-use and free code editor

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 latest version

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),