Spring Boot basis

This article is practical oriented, explaining how to use Spring Cloud to develop microservice projects, and Spring Cloud is based on SpringBoot, so this article will first learn how to use SpringBoot to build a framework.

Spring Boot profile

Spring Boot is a new spring-based framework provided by the Pivotal team, designed to simplify the process of building and developing Spring applications. The framework follows the principle of “convention over configuration” and is configured in a specific way so that developers don’t have to do a lot of XML configuration. Spring Boot is committed to being a leader in the burgeoning field of rapid application development.

Spring Boot does not reinvent the wheel, but encapsulates the original Spring framework, and it integrates libraries to simplify development. In other words, Spring Boot is a big container.

The Spring Boot website describes it as follows:

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications thatyou can “just run”.

We take an opinionated view of the Spring platform and third-party libraries so you can get startedwith minimum fuss. Most Spring Boot applications need very little Spring configuration.

From the above description, we can see that Spring Boot gives us a new application deployment solution that makes it easy to create standalone, production-grade Spring-based applications. At the same time, views can be easily built through the Spring platform and third-party libraries.

In fact, Spring Boot is integrated with Tomcat by default, so you can just compile it into a JAR package and start the application with Java commands. Most Spring Boot applications require very little Spring configuration.

The first Spring Boot project

In this section, we will create our first Spring Boot project, and you can follow these steps.

(1) Open IntelliJ IDEA, click File→New→Module successively, select Maven in the pop-up dialog box, and click Next button to create a Maven project. Here we type demo-lesson- One in the Artifactld field and com.lynn. Boot in the Groupld field. After creating the project, add the following to pom.xml:

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent< / ArtifactId ><version>2.0.3.RELEASE</version> </ parent> <dependencies> <dependency> <groupId>org.springframework. boot</groupId> <artifactId>spring-boot-starter-web</ artifactId></dependency> </dependencies>Copy the code

Where, the tag declares the parent project of Spring Boot, with a version number defined as 2.0.3.release. We can also notice that the spring-boot-starter-Web dependency is declared in the tag, which provides support for Spring MVC.

(2) Write the Application startup class Application:

package com.lynn.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot. autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args){ SpringApplication.run(Application.class,args); }}Copy the code

The power of Spring Boot is that you can launch Web applications directly from the Main method. In the code above, we provide an entry point to the application that launches the built-in Web container by calling SpringApplication.run(). We noticed that the @SpringBootApplication annotation was added to the Application class, and we’ll see what it does in Section 2.4.

Tomcat is built into Spring Boot by default. Of course, it also supports other containers, such as Jetty. If we wanted to change the default container to Jetty, we could change the pom.xml file to look like this:

<dependency>
<groupId>org.springframework. boot</groupId>
<artifactId>spring-boot-starter-web</ artifactId><exclusions>
<exclusion>
<groupId>org.springframework . boot</groupId>
<artifactId>spring-boot-starter-tomcat</ artifactId></exclusion>
< / exclusions>< / dependency><dependency>
<groupId>org.springframework .boot</groupId>
<artifactId>spring-boot-starter-jetty</ artifactId></dependency>
Copy the code

In the code above, we remove Tomcat’s dependencies by tagging and add Jetty’s dependencies.

(3) Write the controller to verify the Spring Boot framework:

package com. lynn.boot.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController f @RequestMapping(value = "hello")public String hello(){i return "Hello world!" ; }}Copy the code

In the code above, the @RestController annotation indicates that this class is a Controller class, and its corresponding annotation is @Controller. The @RestController annotation is equivalent to the @Controller annotation combined with the @responseBody annotation. The @requestMapping annotation defines an HTTP request address. By default, there is no limit to the request method. It can be GET, POST, or any other method. For example, method= requestMethod. GET indicates that only GET requests can invoke the HTTP address.

The annotations mentioned above are Spring MVC annotations, and we can easily use Spring MVC annotations here because of the spring-boot-starter-Web dependency added to the dependency in step (1), which integrates Spring MVC.

(4) Run the main method of Application class and access localhost:8080/ Hello to see the interface as shown in Figure 2-1.

From the above examples, we can know that:

  1. Creating a project with Spring Boot is very simple. There are no XML configuration files or Tomcat. With a few simple annotations, you can start a Web application by running the main method.
  2. Spring Boot has Tomcat built-in by default.
  3. Spring Boot uses annotations instead of cumbersome XML configuration.

Configure the properties using YAML files

In the previous section, we implemented a minimal Web project without creating any configuration files. Of course, any configuration of Spring Boot can be done in code. For ease of extension, it introduces “PROPERTIES” and “YAML” files, where common or custom PROPERTIES can be defined.

Basic usage of YAML

Let’s take a look at the general configuration of Spring Boot. The steps are as follows.

Create a configuration file named application.yml in SRC /main/resources and write the following:

Server: servlet: # define context path context-path: /demo# Define project start port port: 8081Copy the code

In the above configuration, server.servlet.context-path defines the context path of the application as /demo, which defaults to l. Server. port defines the startup port of the application, which defaults to 8080, which is set to 8081.

(2) start the project and access localhost: 8081 / demo/hello, you can see the interface as shown in figure 2-1.

In Section 2.2, we started the project with a listening port of 8080 and a context path of /, but we didn’t configure any information because all configuration properties have default values, such as 8080 for the port.

Next, let’s look at the structure of a YAML file. The basic format is:

key1:
key2:
key3: value
Copy the code

We replace it with the form properties, key1.key2.key3=value. Of course, the number of keys is not fixed. It should be noted here that the YAML format is very strict. If the current key is followed by a value, the colon must be followed by at least one space; otherwise, the compilation will fail. Second, each child attribute needs to be separated by a space or Tab character (that is, by pressing the Tab key), otherwise the attribute value may not be correctly fetched.

If we change the YAML file in the above example to the following form:

Server: servlet: context-path: /demo# The colon is followed by the port number port:8081Copy the code

After starting the project, the console will print the following error message:

Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple keyin 'reader ', line 6, column 3:
port:8081
A
could not find expected " : '
in " reader', line 6, column 12:
port:8081
Copy the code

Multi-environment Configuration

In an enterprise application, we might use a development environment for development, a test environment for testing, and a production environment for launch. The configuration is different for each environment, such as the development environment where the database is the local address and the test environment where the database is the test address. So the question arises: how do we generate packages for different environments when we package?

There are many solutions, as follows.

  1. Before each compilation, manually change all configuration information to the current running environment information. This approach results in the need to modify each time, which is cumbersome and error-prone.
  2. Using Maven, configure multiple environments in POM.xml and change settings. XML to the current environment ID before each compilation. The downside of this approach is that you need to specify the environment manually every time, and if the environment is specified incorrectly, you don’t know about it until release.
  3. Create multiple configuration files for different environments, specified by starting commands. This solution is the focus of this section and I highly recommend it.

Next, let’s look at the steps for configuring multiple environments.

(1) Modify the application.yml file as follows:

server:
servlet:
context-path: /demoport: 8081
spring:
profiles:
active: dev
Copy the code

This refers to the current startup environment via spring.profiles. Active.

{profile} is the name of the environment to be specified in the above configuration. For example, if you add a new file named application-dev.yml, you can add the configuration in the file:

server:
port: 8080
Copy the code

And set spring.profiles.active to dev.

When the project is started, you can see that the project listening port has changed to 8080.

You can go ahead and create a multi-environment file, for example, name it application-test.yml, change the listening port to 8082, then change spring.profiles.active to test, and start the project to see the effect. The value of spring.profiles.active is not manually modified during the actual project release, but dynamically modified through the startup command, as detailed in Section 2.7.

Commonly used annotations

As mentioned earlier, Spring Boot is mostly in the form of annotations instead of cumbersome XML configuration. In this section, I’ll walk you through some common annotations.

@SpringBootApplication

In the previous section, did the reader notice that Spring Boot supports the main method for booting? By adding the @SpringBootApplication annotation to the main class we need to start, we can tell SpringBoot that this class is the entry point to the project. Without this annotation, startup will report an error. Readers can try to remove the comment and see the effect.

Looking at the source code for the @SpringBootApplication annotation, you can see that the annotation consists of @SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan. We can replace @SpringBootApplication with the above three annotations, as in:

package com.lynn.boot; import org.springframework . boot.SpringApplication; import org.springframework. boot.autoconfigure.SpringBootApplication; @SpringBootConfiguration @EnableAutoConfiguration@ComponentScan public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Copy the code

The code runs as in Section 2.2.

@SpringBootConfiguration

Classes annotated with @SpringBootConfiguration are considered to be SpringBoot configuration classes. We can do some configuration either in application.yml or in code.

To do this through code, you must add the @SpringBootConfiguration annotation to this class. We can either define the Bean in the class annotated with this annotation or use it to dynamically change some configuration of application.yml with code. For example, create the webConfig class and change the project startup port number:

package com.lynn.boot; import org.springframework.boot.SpringBootConfiguration; import org.springframework . boot.web.server.webServerFactorycustomizer; import org.springframework. boot.web.servlet.server.ConfigurableServletwebServerFactory; @SpringBootConfiguration public class webConfig implements webServerFactorycustomizer<ConfigurableServletwebServerFactory>{ @override public void Customize (ConfigurableServletwebServerFactory factory) {/ / to the code set to start application port factory. The setPort (8888); }}Copy the code

Starting the project, you can see that the listening port has changed to 8888.

Alternatively, you can use the @Configuration annotation, which has the same effect as @SpringBootConfiguration, although SpringBoot officially recommends using the @SpringBootConfiguration annotation.

@Bean

@Bean annotations are method-level annotations that are added mainly to classes with @SpringBootConfiguration annotations and sometimes to classes with @Component annotations. It defines a Bean, similar to the Spring XML configuration file.

Let’s take a look at how to inject a normal class through the @Bean annotation.

(1) Create a common class Person. Add a field name to the class for testing purposes:

package com. lynn.boot. bean; public class Person { private String name; public void setName( String name){ this.name = name; } public String getName() { return name; } @override public String toString({return "Person{"+ "name= ' '+name +'' '}'; }}Copy the code

(2) Add the following code to the webConfig class created in Section 2.4.2:

@Bean public Person person(){ Person person = new Person(); person. setName( "lynn"); return person; }Copy the code

In the above code, we can add the Person object to the Spring container with an @bean annotation, which simplifies the traditional Spring XML approach.

(3) Conduct unit tests. First, add unit test dependencies:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</ artifactId><scope>test</scope>
</dependency>
Copy the code

Spring Boot integrates with the JUnit testing framework by default, which can be integrated by adding the Spring-boot-starter-test dependency. Create a test class in the SRC /main/test directory and write the test code:

package com.lynn.boot.test; import com. lynn.boot.Application; import com. lynn. boot.bean.Person; import org.junit.Test; import org.junit.runner.Runwith; import org.springframework.beans.factory .annotation.Autowired; import org.springframework .boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringUnit4ClassRunner; @SpringBootTest(classes = Application.class) @RunWith(SpringUnit4classRunner.class)public class MyTest { @Autowired private Person person; @Test public void test(){ System.out.print1n(person); }}Copy the code

In the above code, we add the @SpringbooTtest annotation to specify that the entry class is Application, and the @Runwith annotation to specify that the unit test will run in SpringJUnit4ClassRunner, the unit testing framework that uses JUnit4, and then through @au The ToWired annotation injects the Person class and finally prints the Person information through the Test method.

Note: You need to add the @test annotation to the test method to enable unit tests.

When you start the unit test, you can see that the console prints the following information:

Person{name='lynn '}
Copy the code

@value

Usually, we need to define some global variable, and the idea is to define a public static constant and call it if needed. Is there a better alternative? The answer is yes, and that’s the @value annotation in this section.

(1) Create a custom attribute data in application.yml:

Self: message: data: This is my custom propertyCopy the code

The above configuration is not a Spring Boot built-in property, but our custom property.

(2) Modify HelloController class:

package com.lynn.boot.controller;
import org.springframework.beans.factory. annotation.value;import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework .web.bind.annotation.RestController;
@RestController
public class Hellocontroller {
@Value( "${self.message.data}")private String value;
@RequestMapping(value = "hello" ,produces = MediaType.APPLICATION_SON_UTF8_VALUE)public string hello(){
return value;
}
}
Copy the code

The @Value annotation’s parameters need to be wrapped with ${} to wrap the target property, which can be either a Spring built-in property or a custom property.

(3) start the project and access localhost: 8080 / demo/hello, you can see the interface as shown in figure 2-2.

Spring Boot integrated template engine

In the traditional Spring MVC architecture, we typically put JSP and HTML pages in the Webapps directory. But Spring Boot doesn’t have webapps, let alone web.xml, so how do you write an interface?

We can integrate the template engine. Spring Boot officially provides several template engines: FreeMarker, Velocity.Thymeleaf.Groovy, Mustache, and JSP. In this section, we use FrceMarker as an example to explain how Spring Boot integrates with a template engine.

First, add a dependency on FreeMarker in pom.xml:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
Copy the code

Create the static and templates directories under the Resources directory, as shown in Figure 2-3. The static directory is used to store static resources such as CSS, JavaScript, and HTML, and the templates directory is used to store template engine files.

Then create the index.ftl file under the Templates directory and add the following:

<! DOCTYPE html> <html> <head></head><body> <h1>Hello world! </h1></body> </html>Copy the code

Next, create the controller class:

@Controller public class Pagecontroller { @RequestMapping("index.html")public String index()i return "index" ; }}Copy the code

Finally, start the Application. The Java access localhost: 8080 / demo/index. The HTML, you can see the interface as shown in figure 2-4.

In the code above, we want to return the FreeMarker template page, so we must define it as @Controller, not @RestController as defined earlier. @restController is a combination of @Controller and @responseBody. Annotated as @restcontroller, SpringMVC’s ViewResolver will not work, that is, it will not return HTML or JSP pages. The main purpose of a ViewResolver is to resolve a logical view name into a real view. When we annotate a Controller as @Controller and return a view name, the ViewResolver finds the actual view by that view name and presents it to the client.

Change the default JSON converter

Spring Boot uses the Jackson engine by default to parse the objects returned by the controller. The engine is not as fast and convenient as third-party engines (FastJson, Gson, etc.). This section shows you how to replace the default converter with a FastJson converter.

Add FastJson dependency to POM.xml:

< the dependency > < groupId > com. Alibaba < / groupId > < artifactId > fastjson < / artifactId > < version > 1.2.47 < / version > < / dependency >Copy the code

(2) Modify webConfig class, add method to it and set FastJson converter:

@SpringBootConfiguration public class webConfig extends webMvcConfigurationSupport{ @override public void configureMessageConverters(List<HttpMessageConverter< ? >> converters) { super.configureMessageConverters(converters); Fast3sonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); FastJsonconfig fast]sonconfig=new FastsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat ); List<MediaType> mediaTypeList = new ArrayList<>(); /I/ Set the encoding to UTF-8 mediatypely.add (MediaType.APPLICATION_JSON_UTF8); fastconverter.setSupportedMediaTypes(mediaTypeList); fastconverter.setFast]sonConfig(fastsonconfig); converters.add(fastConverter); }}Copy the code

First of all should inherit webMvcConfigurationSupport classes, this class provides a Spring Boot support for Spring MVC. Then rewrite configureMessageConverters method, the method to configure the message converters. If a third-party framework wants to handle requests and responses in Spring MVC, it needs to implement the HttpMessageConverter interface. FastJsonHttpMessageConverter in the above code is so, it implements the HttpMessageConverter interface, and through the Fast] FastJson sonConfig setting processing parameters, If the encoding is set to UTF-8 via MediaType, it is finally added to HttpMessageConverter.

This allows Spring MVC to replace the JSON parsing engine with FastJson when processing the response.

Package and publish to the server

Spring Boot supports two ways to start applications: JAR and WAR. The following describes how to start applications in these two ways.

Publish jar packages using built-in Tomcat

Since Tomcat is built into Spring Boot, we can package the project into a JAR and run our Web project through Java commands as follows.

(1) Add the following content to the pom.xml file:

<build> <finalName>api</finalName><resources> <resource> <directory>src/main/resources</ directory><filtering>true</filtering> </resource> < /resources><plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</ artifactId><configuration> <fork>true</fork> <mainclass>com. lynn.boot.Application</mainclass> </ configuration> <executions> <execution> <goals> <goal>repackage</goal></goals> </ execution></executions></plugin> <plugin> The < artifactId > maven - resources - the plugin < / artifactId > < version > 2.5 < / version > < configuration > < encoding > utf-8 < / encoding > <useDefaultDelimiters>true</useDefaultDelimiters>< / configuration> </plugin> <plugin> <groupId>org.apache. Maven. Plugins < / groupId > < artifactId > maven - surefire - plugin < / artifactId > < version > 2.18.1 < / version > < configuration > <skipTests>true</skipTests></configuration> </plugin> <plugin> . < groupId > org, apache maven plugins < / groupId > < artifactId > maven - compiler - plugin < / artifactId > < version > 2.3.2 < / version > <configuration> <source>1.8</ source><target>1.8</target></configuration> </plugins> </build>Copy the code

In Pom.xml, tags define some information about Maven compilation and packaging. In it, some parameters for compilation are set for the packaged file name. Maven supports third-party plugins, and the Spring Boot plugin is spring-boot-maven-plugin, which specifies the Boot class. The Maven-Surefire-plugin is a maven-surefire-plugin for building test cases. If there is a unit test class, it will execute the unit test after compilation and will be packaged only after the unit test is successful. If you do not want to perform unit tests, set this to true. I recommend setting it to true, as false will take too long to pack. If there are add, delete, or change tests to the database in the unit test class and they are executed at compile time, the original data may be affected. Maven-compiler-plugin is a plugin provided by Maven with the specified compiler version. 1.8 in the above code indicates that JDK 1.8 is used for compilation.

(2) Compile and package using MVN Clean Package, as shown in Figure 2-5.

(3) Upload the packaged content to the server and run the following command:

java -jar api.jar
Copy the code

This will launch a Spring Boot application. As mentioned earlier, you can use command parameters to set different environments or dynamically set parameters, so how to set? Run the following command to set the environment:

java -jar api.jar --spring.profiles.active=dev
Copy the code

When the application starts, the configuration information in application-dev.yml is pulled. If you want to change any property value, just add the name of the property and the property value to be changed.

Release it as a WAR package

In addition to compiling to jar packages for distribution, Spring Boot also supports compiling to WAR packages for deployment to Tomcat. (1) Change the application packaging format to WAR in POM.xml:

<packaging>war</packaging>
Copy the code

This is the file that tells Maven what suffix to compile into.

(2) Modify the content under the label as follows:

<build> <finalName>api</finalName><resources> <resource> <directory>src/main/resources</directory><filtering>true</filtering> </resource> </ resources><plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin< / artifactId></plugin> <plugin> The < artifactId > maven - resources - the plugin < / artifactId > < version > 2.5 < / version > < configuration > < encoding > utf-8 < / encoding > < / configuration> </plugin> <plugin> . < groupId > org, apache maven plugins < / groupId > < artifactId > maven - surefire - plugin < / artifactId > < version > 2.18.1 < / version > <configuration> <skipTests>true</skipTests></configuration> </plugin> </plugins> < /build>Copy the code

Similar to section 2.7.1, the maven-resources-plugin is added to compile files in the Resources directory. This is not required in the spring-boot-Maven-plugin, because the compiled WAR is deployed on external Tomact and runs on the Tomcat container without executing the main method.

(3) Add a Tomcat dependency and set it to provided. The purpose of this is to remove the Tomcat package at compile time, otherwise an error may be reported at startup. We also cannot remove the Tomcat package directly with the tag, since we need to start it with the Application class for local development. The relevant codes are as follows:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope></ dependency>
Copy the code

(4) modify the type of Application, it inherits the SpringBootServletInitializer classes, and wrote the configure method, so that Tomcat can load at startup Spring Boot Application:

@SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[]args) { SpringApplication.run( Application.class, args); } @override protected SpringApplicationBuilder configure(SpringApplicationBuilder application){ return application. sources(Application.class); }}Copy the code

In the code above, if we were using external Tomcat to start the application, we could remove the main method. Because Tomcat executes the configure method on startup, the configure method calls the Source method and specifies the Application class, which acts as the main method.

(5) Compile and package files in WAR format using MVN Clean Package, and copy them to Tomcat. Start Tomcat, and you can see that the application can be accessed normally. If the application is started using external Tomcat, the port specified by server.port is invalid and the port specified by Tomcat is used instead.

Unlike jar packages, you cannot specify the runtime environment or other parameters that you want to change dynamically during startup with WAR launcher. Besides, the context path is based on the name of WAR package, and you need to install Tomcat yourself, which is quite troublesome. Therefore, I recommend the JAR package as the preferred startup mode.

WebFlux quick start

Spring Boot 2.0 brings WebFlux, uses Reactor as the preferred streaming framework, and provides support for RxJava. With WebFlux, we can build an asynchronous, non-blocking application. Let’s take a look at WebFlux.

(1) Create a Maven project based on Spring Boot, name it demo-de-one-webFlux, and add dependency on webFlux to POP.xml file:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</ artifactId></ dependency>
Copy the code

(2) Write a Handler that wraps the data:

@Component public class HelloHandler { public Mono<ServerResponse> hello(ServerRequest request) { return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN) .body(BodyInserters.fromobject( "Hello, world ! ")); }}Copy the code

This class customizes a method that returns a Mono object. Here you set the data to be returned in the Body method of ServerResponse.

(3) Write the interface class, that is, define what we usually call the routing address (interface address):

@springBootConfigurationpublic class He1loRouter { @Bean public RouterFunction<ServerResponse> routeHello(HelloHandler helloHandler){ return RouterFunctions.route(RequestPredicates.GET( "/hello") .and(RequestPredicates. Accept (MediaType.TEXT_PLAIN)), helloHandler: : hello); }}Copy the code

Since the route needs to be registered with the Spring container, the class also needs to add the @SpringBootConfiguration annotation and identify the returned route as a Bean so that it can be registered with the Spring container.

In the code above, we define a method called routeHello and return a RouterFunction object. In the RouterFunction, specify the route address as /hello and specify the Handler and corresponding method, the HelloHandler created earlier. This returns the data set by the Handler’s Hello method via the route address/Hello.

(4) Start application. Java and access localhost:8080/hello. You can see that the browser displays HelloWorld normally. From the console, we can clearly see that it is started with NettyServerR:

Netty started on port(s):808e
Copy the code

So we set up a routing address. Careful readers can see that the above code is too cumbersome, and Spring Boot takes this into account. To facilitate the migration of MVC applications to WebFlux, Spring Boot is officially compatible with WebFlux and MVC, that is, we can use MVC annotations to create WebFlux routing addresses.

(1) Create Hellocontroller and write the following code:

@RestController public class Hellocontroller { @RequestMapping(value = "hello")public Mono<String> hello({ return Mono.just( "Hello world! "); }}Copy the code

As you can see, the code above is very similar to the code we wrote before, except that we need to return the Mono object, and WebFlux wraps the data back into Mono by calling the Just method. The type of argument passed by the just method depends on the type specified by the generics following Mono.

(2) Start application.java, and we get the same result as the previous code.

summary

Through this tutorial, we learned the basics of Spring Boot and felt the elegance of YAML.

This article covers common annotations, integration with the Spring Boot default engine, changes to JSON converters, and compiling and deploying applications that might be used in a real-world project. Finally, the popular WebFlux framework is introduced. We’ll learn more about other Spring Boot features later in the series.

Three things to watch ❤️

If you find this article helpful, I’d like to invite you to do three small favors for me:

  1. Like, forward, have your “like and comment”, is the motivation of my creation.

  2. Follow the public account “Java rotten pigskin” and share original knowledge from time to time.

  3. Also look forward to the follow-up article ing🚀

  4. [666] Scan the code to obtain the learning materials package

Article is not original, and all of us feel while reading the article good remember thumb up forward + attention oh ~ this article source: www.toutiao.com/i6917900803…