Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the core concepts of Spring Boot and Spring MVC in Spring

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of what is the core concept of Spring Boot and Spring MVC in Spring, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this Spring core concept of Spring Boot and Spring MVC. Let's take a look at it.

1. Comparison of Spring Boot, Spring MVC and Spring

First of all, you need to understand one thing: the purpose of the Spring Boot project is not to replace Spring and SpringMVC, but to make them easier to use.

Spring framework

The core features of the Spring framework are dependency injection DI (Dependency Injecttion) and control inversion IOC (Inversion Of Control). If you can use DI and IOC properly, you can develop loosely coupled and scalable applications.

Spring MVC

Spring MVC provides a friendly way to develop Web applications. By using things like Dispatcher Servlet,ModelAndView and View Resolver, you can easily develop Web applications.

Spring Boot

The biggest disadvantage of Spring and Spring MVC is that there are a large number of configurations, and these configurations are highly similar in different projects. This leads to repeated configuration, tedious and messy!

Spring Boot expects to solve this problem by combining autoconfiguration with starters. In addition, Spring Boot provides capabilities to build applications that can be used in production environments more quickly.

II. Automatic configuration of Spring Boot

There are a large number of XML or Java Bean configurations in Spring and Spring MVC applications. Spring Boot provides a new solution and a new way of thinking to solve this problem.

The way springboot thinks: is it possible to be smarter? when some new jar packages and configurations are added to Spring, it can automatically affect the loading of bean in the application. For example, when Spring MVC JAR is in the classpath, Dispatcher Servlet is automatically configured. Of course, when these automatic default configurations do not meet our requirements, we can modify them. Modify the Bean that was loaded before, and some other Bean will be loaded automatically after the configuration change.

What is Spring Boot Starter?

Spring Boot Starter is a collection of dependent third-party class libraries.

If you want to develop a web application, you can introduce spring-boot-starter-web through package management tools (such as maven), instead of introducing so many of the following dependent class libraries, spring-boot-starter-web helps you introduce the following common class libraries at once.

Spring-spring core, beans, context context, AOP facing aspect

Web MVC-Spring MVC

Serialization and deserialization of Jackson-JSON data

Validation-Hibernate parameter check and check API

Embedded Servlet Container-Tomcat

Log framework Logging-logback, slf4j

What is Spring Boot Starter Parent

All Spring Boot projects use spring-boot-starter-parent as the parent project of the application by default.

Org.springframework.boot spring-boot-starter-parent 2.0.0.RELEASE

The advantage of inheriting the parent project is that it unifies the java version configuration and other versions that depend on the class library. In other words, the third-party class library you introduce does not add the version number, the parent project manages the version for you, and it has been tested for compatibility. It is more compatible than introducing a random version yourself.

Of course, the parent project can only help you manage the versions of some commonly used class libraries, if you introduce some less commonly used jar, you still have to manage the version number and compatibility!

5. Embedded web container

Spring boot is packed as a jar package, which contains an embedded web container: tomcat by default. You can simply start a web service with the following command:

Java-jar springboot-demo.jar

This is more conducive to the deployment of micro-services and the construction, startup and expansion of micro-services. Spring Boot also supports Jetty and Undertow as web containers.

VI. Spring Data

The goal of Spring Data is to provide a more friendly way, or API, to access data. Includes support for relational databases and NOSQL data. For example:

Spring Data JPA-API for relational database operation, friendly and easy to use

Operation API of Spring Data MongoDB-MongoDB

Spring Data REST-automatically generates a service layer API from the persistence layer Repositories, exposing the REST APIs interface. It works super well!

Of course, Spring Data has more useful features and support waiting for you to explore!

7. New features of spring boot2.x 7.1. Basic environment upgrade

Minimum JDK 8, support JDK 9, no longer support Java 6 and 7. Spring Boot 2.0 requires Java 8 as the minimum version, and many existing API have been updated to take advantage of the features of Java 8.

For example, the default methods on the interface, function callbacks, and new API, such as javax.time.

If you are using Java 7 or earlier, you need to upgrade your JDK before developing Spring Boot 2.0 applications.

7.2. Dependent component upgrade

Jetty 9.4 Jetty is an open source Servlet container that provides a runtime environment for Java-based Web content, such as JSP and Servlet. Jetty is written in the Java language, and its API is released as a set of JAR packages.

Tomcat 8.5 Apache Tomcat 8.5.x is designed to replace 8.0.x and fully supports Java 9.

Flyway 5PowerFlyway is a database version management tool that applies, manages and tracks database changes independently of the database. In popular terms, Flyway can manage different people's SQL scripts in the same way that SVN manages different people's code, thus achieving database synchronization.

Hibernate 5.2 Magi hibernate is a very popular ORM framework.

The Gradle plug-in for Gradle 3.4 and Spring Boot has been largely rewritten with significant improvements.

Thymeleaf 3.0 Thymeleaf 3 has a very big performance improvement over Thymeleaf 2.

7.3. Default software replacement

The default database connection pool has been switched from Tomcat to HikariCP,HikariCP is a high-performance JDBC connection pool, and Hikari means "light" in Japanese.

The redis client defaults to Lettuce, replacing Jedis.Lettuce as a scalable, thread-safe Redis client for synchronous, asynchronous, and reactive use. Multiple threads can share the same RedisConnection, which leverages the excellent Netty NIO framework to efficiently manage multiple connections and supports advanced Redis features such as Sentinel, clustering, pipelining, automatic reconnection, and the Redis data model.

7.4. The introduction of new technologies

Responsive programming WebFlux, an important change, which will be shown in detail in subsequent chapters

Support for Quartz,Spring Boot 1.0 does not provide support for Quartz. Various integration schemes have emerged before, and Spring Boot 2.0 provides the easiest way to integrate.

Support for Kotlin

Supported by JOOQ, JOOQ is a toolkit for accessing relational databases based on Java. JOOQ not only absorbs the simplicity and security of traditional ORM operating data, but also retains the flexibility of native SQL, it is more like the middle layer between ORMS and JDBC.

7.5. Colored egg

Src/main/resources path in the Spring Boot project to create a new banner.txt file, the file to write some characters, the start of the project will find that the default Banner has been replaced, to Spring Boot 2.0 can now support Gif file printing, Spring Boot 2.0 in the project start, will print each picture of the Gif image in the log in order, all the screen printing is completed before the start of the Spring Boot project.

This is the end of the article on "what are the core concepts of Spring Boot and Spring MVC in Spring?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the core concepts of Spring Boot and Spring MVC in Spring". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report