Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Building microservices: quickly build Spring Boot projects

Shulou Source: shulou.com Published: 2022-06-03 03:05:22 10月27日 Update

Introduction to Spring Boot:

Spring Boot is a new framework provided by the Pivotal team, which is designed to simplify the initial building and development process of new Spring applications. The framework is configured in a specific way so that developers no longer need to define a templated configuration. In this way, Spring Boot is committed to becoming a leader in the booming field of rapid application development (rapid application development) (introduced on the official website).

Spring Boot features:

Create a stand-alone Spring application

Embedded Tomcat, no need to deploy WAR files

Simplify Maven configuration

Automatically configure Spring

Provide production-ready features such as metrics, health check and external configuration

Absolutely no code generation and no configuration requirements for XML

Getting started:

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

2. Fill in the relevant project information, jdk version, etc. (please refer to the following figure)

3. Click Generate Project, and you will generate a compressed package of the maven project, and download it.

4. After decompression, use eclipse,Import-> Existing Maven Projects-> Next-> Select the decompressed folder-> Finsh

Introduction to the project structure:

As shown in the following figure, the infrastructure of Spring Boot consists of three files:

Src/main/java-Program Development and main Program Portal

Src/main/resources-profile

Src/test/java-Test Program

Spring Boot recommended project structure:

Root directory: com.example.myproject

1) domain: entity class (com.example.domain)

2) Dao: data access layer (com.example.repository)

3) Service: data service interface layer (com.example.service)

ServiceImpl: data service implementation layer (com.example.service.impl)

4) Controller: front-end controller (com.example.controller)

5) utils: tool class (com.example.utils)

6) constant: constant API class (com.example.constant)

7) config: configuration information class (com.example.config)

8) dto: data transfer object (Data Transfer Object), which is used to encapsulate the relationship between multiple entity classes (domain) without destroying the original entity class structure (com.example.dto)

9) vo: view wrapper object (View Object), which is used to encapsulate the data requested by the client, prevent some data from being leaked, ensure data security, and do not destroy the original entity class structure (com.example.vo)

Introduce the Web module:

Add modules that support Web in pom.xml

one

2 org.springframework.boot

3 spring-boot-starter-web

four

Run the project:

1. Create a controller

Package com.example.annewebsite_server.controller

Import org.springframework.web.bind.annotation.GetMapping

Import org.springframework.web.bind.annotation.RestController

@ RestController

Public class HelloController {@ GetMapping ("/ hello") br/ > @ GetMapping ("/ hello")

Return "Hello Spring Boot!"

}

}

2. Start the project entry

3. The project was launched successfully

4. Access in the browser (http://localhost:8080/hello)

The above is a Spring Boot project building process, hope to be able to learn Spring Boot colleagues to bring some help, deficiencies, welcome to correct.

Tags: Project configuration data structure entity file development program application service information entry object interface way framework module process encapsulation generation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn MySQL MariaDB Docker