Advantages of SpringBoot

1. What is SpringBoot

In the use of traditional Spring for Java EE (Java Enterprise Edition) development, a large number of XML files exist in the project, resulting in the JavaEE project becoming cumbersome and cumbersome configuration and integration of third-party framework configuration, resulting in Reduced development and deployment efficiency.

Spring Boot is not a solution to replace Spring, but a tool that is tightly integrated with the Spring framework to enhance the Spring developer experience. At the same time, it integrates a large number of commonly used third-party library configurations. These third-party libraries in Spring Boot applications can almost be used out-of-the-box with zero configuration. Most Spring Boot applications only need very With a small amount of configuration code (Java-based configuration), developers can focus more on business logic.

2. Why learn SpringBoot

1. From the official point of view

2. From the advantages of Spring

①Good genes

Because SpringBoot was born with Spring 4.0, boot means boot, that is, its role is to help developers quickly build the Spring framework, so SpringBoot inherits the excellent genes of Spring, and it is more convenient to develop in Spring. fast.

② Simplify dependencies

For example, we want to create a web project. Friends who use Spring know that when using Spring, you need to add multiple dependencies to the pom file, and Spring Boot will help developers quickly start a web container. In Spring Boot , we just need to add the following starter-web dependency to the pom file.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

After we click into the dependency, we can see that the Spring Boot starter-web already contains multiple dependencies, including the dependencies that need to be imported in the Spring project before. Let's take a look at some of them, as follows:

<!-- .....省略其他依赖 -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.7.RELEASE</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.0.7.RELEASE</version>
    <scope>compile</scope>
</dependency>

It can be seen from this that Spring Boot greatly simplifies our coding. We do not need to import dependencies one by one, but only one dependency.

③ Simplified configuration

Although Spring is a lightweight framework for Java EE, it was once considered "configuration hell" due to its cumbersome configuration. Various XML and Annotation configurations can be dazzling, and if there are too many configurations, it is difficult to find the cause if something goes wrong. Spring Boot uses Java Config more to configure Spring. for example:

I create a new class, but I don't use the @Service annotation, that is to say, it is a normal class, so how do we make it a Bean for Spring to manage? Only need two annotations @Configuration and @Bean, as follows:

public class TestService {
    public String sayHello () {
        return "Hello Spring Boot!";
    }
}

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JavaConfig {
    @Bean
    public TestService getTestService() {
        return new TestService();
    }
}

@Configuration indicates that the class is a configuration class, and @Bean indicates that the method returns a Bean. In this way, the TestService is used as a bean for Spring to manage. In other places, if we need to use the bean, as before, it can be injected directly using the @Resource annotation, which is very convenient.

@Resource private TestService testService;

In addition, in terms of deployment configuration, Spring has multiple xml and properties configurations, and only one application.yml is needed in Spring Boot.

④ Simplified deployment

When using Spring, we need to deploy tomcat on the server when the project is deployed, and then put the project into a war package and throw it into tomcat. After using Spring Boot, we do not need to deploy tomcat on the server, because Spring Boot has embedded tomcat , we only need to make the project into a jar package and use java -jar xxx.jar to start the project with one click.

In addition, the basic requirements for the operating environment are also reduced, and it is sufficient to have JDK in the environment variable.

⑤ Simplified monitoring

We can introduce the spring-boot-start-actuator dependency and directly use the REST method to obtain the runtime performance parameters of the process, so as to achieve the purpose of monitoring, which is more convenient. However, Spring Boot is just a micro-framework, it does not provide the corresponding service discovery and registration functions, there is no peripheral monitoring integration solution, and there is no peripheral security management solution. Therefore, in the micro-service architecture, Spring Cloud is also required to be used together.

3. From the perspective of future development trends

Microservices are the trend of future development, and projects will gradually shift from traditional architectures to microservices architectures, because microservices allow different teams to focus on a smaller scope of work responsibilities, use independent technologies, and deploy more safely and frequently. It inherits the excellent features of Spring, is in the same vein as Spring, and supports various REST API implementations. Spring Boot is also a technology that is highly recommended by the government. It can be seen that Spring Boot is a major trend in future development.

Guess you like

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