Purpose of this blog
Complete the construction of the Spring Boot basic project and implement a simple Http request processing.
Introduction to spring boot
- Spring Boot is a new framework provided by the Pivotal team, designed to simplify the initial setup and development of new Spring applications. The framework uses a specific way to configure, so that developers no longer need to define boilerplate configuration. In this way, Spring Boot aims to be a leader in the burgeoning field of rapid application development.
- In the previous spring projects, there were a lot of tedious configurations, and they were basically copied and pasted when used. Spring Boot allows us to easily and quickly build Spring Web applications without too much configuration, out of the box, without code generation, and without XML configuration, so that we can quickly use the spring framework.
Build the spring boot project
Version: java 1.8 & spring boot 1.5.10
Generate basic projects through SPRING INITIALIZR
tools
-
access:
http://start.spring.io/
- Select the build tool
Maven Project
, Spring Boot version1.5.10
, and some basic project information, as shown in the following figure - Group fills in the group name, Artifact fills in the module name, and 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 download the project zip file.
Unzip the project package and Maven
import it as a project with the IDE
Take for IntelliJ IDEA
example:
- Select from the menu
File
–>New
–>Project from Existing Sources...
- Select the unzipped project folder and click
OK
- Click
Import project from external model
and selectMaven
, clickNext
until the end; - If your environment has multiple versions of JDK,
Java SDK
please selectJava 7
the above version when choosing.
Project structure analysis
as the picture shows:
The creation of the basic project is completed through the above steps. The Spring Boot infrastructure consists of three files (the specific path is based on all the differences in the Group filled in when the user generates the project):
src/main/java
The following program entry:TestApplicatino
src/main/resources
config file under:application.properties
src/test/
The following test entry:TestApplicationTests
Both the generated TestApplication
and the TestApplicationTests
class can be directly run to start the currently created project. Since the project is not currently equipped with any data access or Web modules, the program will end running after Spring is loaded.
write controller service
- Create
package
namedcom.zhongCe.test.web
(modify according to actual situation) - Create a
IndexController
class with the following content:
- Start the main program and open the browser to access
http://localhost:8080/index
- You can see the page output
Hello World
end