Build a simple spring boot project

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 INITIALIZRtools

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

  2. Select the build tool Maven Project, Spring Boot version 1.5.10, and some basic project information, as shown in the following figure  
  3. 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;
  4. Click Generate Projectto download the project zip file.

Unzip the project package and Mavenimport it as a project with the IDE

Take for IntelliJ IDEA example:

  1. Select from the menu File–> New–>Project from Existing Sources...
  2. Select the unzipped project folder and clickOK
  3. Click Import project from external modeland select Maven, click Nextuntil the end;
  4. If your environment has multiple versions of JDK, Java SDKplease select Java 7the 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/javaThe following program entry:TestApplicatino
  • src/main/resourcesconfig file under:application.properties
  • src/test/The following test entry:TestApplicationTests

Both the generated TestApplicationand the TestApplicationTestsclass 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 packagenamed com.zhongCe.test.web(modify according to actual situation)
  • Create a IndexControllerclass with the following content:

       

  • Start the main program and open the browser to accesshttp://localhost:8080/index

       

  • You can see the page outputHello World

       

end

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325471983&siteId=291194637