The main function of building plug-ins is to package the project into an executable super JAR (uber-JAR), which includes putting all the dependencies of the application into the JAR file and adding a description file for the JAR, which allows you to run the application with java-jar.

In addition to building plug-ins, spring-boot-starter-parent is also used as the upper level, so that Maven's dependency management function can be used to inherit dependency versions of many common libraries, so you don't need to specify the version number when you declare dependencies. Note that there is no specified version of dependency in this pom.xml

Start Dependence

First of all, assuming there is no start dependency, with Spring MVC, we know the following points:

Which Spring dependencies do you need?

Thymeleaf Group and Artifact ID

Which version of Spring Data JPA to use

Compatibility issues

This is just to develop a Spring Web application that uses the Thymeleaf view to persist data through JPA. But before we tap into the code, we need to understand what we need to add to POM.XML to support our project.

This dependency list is good and should work, but what do you know? We still have a long way to go before we start building without writing a single line of code?

Let's step back and think about what we're going to do. We want to build an application with the following functions.

This is a Web application.

It uses Thymeleaf

It persists data in relational databases through Spring Data JPA

Wouldn't it be simpler if we only specified these functions in the build file so that the build process could figure out what we wanted for itself? This is what Spring Boot relies on to start with.

Transfer dependencies introduced by coverage start dependencies

Take Spring Boot's Web Start Dependency as an example, which delivers dependencies on Jackson JSON libraries. If you are building a REST service that produces or consumes JSON resource representations, it will be useful. However, to build traditional human-oriented Web applications, you may not need Jackson. Although it won't do any harm to add it in, you can lose weight for your project by eliminating its transmission dependency.

On the other hand, maybe the project needs Jackson, but you need to build it with another version of Jackson, not the one in the Web Start Dependency. Suppose the Web Start Dependency refers to Jackson 2.3.4, but you need to use 2.4.3. In Maven, you can express your appeal directly in pom.xml, just like this:

Use automatic configuration

When Spring Boot is added to an application, there is a JAR file called spring-boot-autoconfigure, which contains many configuration classes. Each configuration class is in the application's Classpath and has the opportunity to contribute to the application's configuration. These configuration classes have configurations for Thymeleaf, Spring Data JPA, Spiring MVC, and many other things that you can choose to use in Spring applications.

All these configurations are so different because they take advantage of Spring's conditional configuration, a new feature introduced by Spring 4.0. Conditional configurations allow configurations to exist in applications, but they are ignored until certain conditions are met.

In Spring, you can easily write your own conditions. All you have to do is implement the Condition interface and override its matches() method. For example, the following simple conditional class will only take effect if JdbcTemplate exists in Classpath.

In this example, the MyService Bean is created only when the condition of the JdbcTemplateCondition class holds. That is to say, MyService Bean is created on the condition that there is JdbcTemplate in the Classpath. Otherwise, the bean declaration will be ignored.

These configuration classes constitute the automatic configuration of Spring Boot. Spring Boot uses conditional configuration by defining several special conditional annotations and applying them to configuration classes

Conditional annotation

Configuration Effective Conditions

@ConditionalOnBean

Configured a particular Bean

@ConditionalOnMissingBean

No specific Bean is configured

@ConditionalOnClass

Classpath has a specified class

@ConditionalOnMissingClass

Lack of specified classes in Classpath

@ConditionalOnExpression

The result of a given Spring Expression Language (SpEL) expression is true

@ConditionalOnJava

Java version matches a specific value or a range value

@ConditionalOnJndi

A given JNDI location in a parameter must exist, and if no parameter is given, there must be a JNDI Initial Context.