Spring Boot 2. X Series tutorial: seven days from scratch to master spring boot – continuous update

brief introduction

Since the birth of spring, spring has become the de facto J2EE standard. As a lightweight J2EE application framework, spring is designed for the complex characteristics of EJB. Finally, there is no doubt that spring has won the final victory with its simplicity, comprehensibility and availability.

Spring has been making continuous progress from the initial XML configuration to the later annotation configuration, but is there a way to run spring applications without configuration? So spring boot came into being.

Springboot is a new open source lightweight framework developed by pivot team in 2013 and released its first version in April 2014.

Spring boot makes your enterprise applications easier to write and run. It also integrates many commonly used third-party lib libraries, avoiding the trouble of manually referencing configuration.

Running the most complex spring applications with the simplest configuration should be the ultimate goal of spring boot.

At the same time, spring boot can get rid of XML configuration as much as possible, and can provide various operation modes, including independent operation and internal operation of the server, so as to facilitate our use.

Basic operation of spring boot

The latest spring boot version is 2.3 0. Release, which requires at least jdk8 support and spring framework 5.2 6.RELEASE。

In terms of building tools, Maven 3.3 + and gradle 6.3 + are required.

In terms of servers, spring boot has three built-in servers: Tomcat 9.0, jetty 9.4 and underworld 2.0. Spring boot needs to be deployed in the environment of servlet 3.1 + to run normally.

In terms of installation, there are two ways to install spring boot. The first is to introduce it in the form of jar package in Maven or gradle. The advantage of this way is intuitive, and the configuration of spring boot can be seen in the project.

The second way is to use the spring boot cli, through which you can also run groovy scripts.

Several basic modules in spring boot are listed below:

You can refer to the tutorial files listed below step by step. After running, I believe you will have a deep understanding of spring boot.

Construction and deployment of spring boot

Maven or gradle are indispensable for developing Java projects. Compared with gradle, Maven may be more commonly used. To use maven, you need to install Maven. What if some users don't want to install Maven? In other words, if you don't want to install Maven globally, you can use the project level Maven wrapper to implement this function.

If you use IntelliJ idea to develop the spring boot project, if you choose to create the project from spring initializr, Maven wrapper will be automatically applied in the project. Simply put, there will be two more files under the project directory: mvnw and mvnw cmd。

After we have created the spring boot application, how can we run it in the build environment? If you only run the program in the original Java jar way, you can't guarantee the robustness and stability of the program. The best way is to register the program as a service.

Spring boot tool

Spring boot actuator was available when the first version of spring boot was released. It provides a series of product level features for spring boot: monitoring applications, collecting metadata, running status or database status.

Using spring boot actuator, we can directly use these features without implementing them ourselves. It uses HTTP or JMX to interact with the outside world.

Spring boot provides us with a convenient environment for developing spring boot applications. At the same time, in order to facilitate our development of spring boot applications, spring boot has launched the spring boot devtool tool to facilitate us to develop and test spring boot applications more quickly.

Earlier, we talked about the actuator of spring boot. However, spring boot actuator only provides interfaces one by one, which needs to be integrated into the monitor program by ourselves. Today we will explain an excellent monitoring tool, spring boot admin. It uses a graphical interface to make our spring boot management easier.

Spring boot test

Testing is a necessary function of an application. It can ensure the robustness and stability of the program, especially in CI environment.

Spring boot has a special spring boot starter test, which can be easily tested in spring boot.

Using JPA in spring boot

The full name of JPA is java persistence API (JPA), which is a standard of storage API, and spring data JPA is an implementation of JPA, which allows us to easily access data. Write the Dao layer interface according to the agreed method naming rules, so as to realize the access and operation of the database without implementing the interface. At the same time, it provides many functions other than crud, such as paging, sorting, complex query and so on.

Spring data JPA can be regarded as a secondary encapsulation of hibernate. Using JPA in spring boot is very convenient.

Integration of spring boot and third-party systems

For the convenience of developers, spring boot has integrated many third-party services, and we can use them directly.

Even if spring does not officially provide integration, the third-party system itself will provide integration with spring, because spring is too widely used.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>