从0开始学习SpringBoot-第2天

第三部分:Using Spring Boot(使用SpringBoot)

This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly special about Spring Boot (it is just another library that you can consume(消耗)), there are a few recommendations(推荐) that, when followed, will make your development process just a little easier.
这一章将更详细的讲解SpringBoot的用法。包括构建系统,自动配置和运行应用以及SpringBoot的最佳实战等等。虽然SpringBoot没有什么特别的(仅仅是你可以选择的一个框架),有几个推荐的方法,当遵循这些方法的时候,将会使你的开发更容易些。

13.Build systems
It is strongly recommended that you choose a build system that supports dependency management, and one that can consume artifacts published to the “Maven Central” repository. We would recommend that you choose Maven or Gradle. It is possible to get Spring Boot to work with other build systems (Ant for example), but they will not be particularly well supported.
强烈推荐使用一个支持依赖管理和发布到maven中央仓库的构建系统。我们建议选择Maven和Gradle。也可以用别的,比如Ant,但他们不会明确的被支持。

13.1 Dependency management
Each release of Spring Boot provides a curated list of dependencies it supports. In practice, you do not need to provide a version for any of these dependencies in your build configuration as Spring Boot is managing that for you. When you upgrade Spring Boot itself, these dependencies will be upgraded as well in a consistent way.
依赖管理
每个发布的SpringBoot版本都提供了支持的依赖清单。在使用过程中,如果使用SpringBoot为你管理配置的时候,你不需要提供任何依赖的版本。当你升级SpringBoot的时候,那些依赖也会跟着升级。

You can still specify a version and override Spring Boot’s recommendations if you feel that’s necessary.
如果需要去修改的话,你可以重写SpringBoot的推荐配置

The curated list contains all the spring modules that you can use with Spring Boot as well as a refined list of third party libraries. The list is available as a standard Bills of Materials (spring-boot-dependencies) and additional dedicated support for Maven and Gradle are available as well.
这个清单包含SpringBoot以及一个精简的第三方lib列表。这个清单可以用作基本的Bills of Materials 并且 也支持Maven和Gradle

13.2 Maven
Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:

Java 1.6 as the default compiler level.
UTF-8 source encoding.
A Dependency Management section, allowing you to omit <version> tags for common dependencies, inherited from the spring-boot-dependencies POM.
Sensible resource filtering.
Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).
Sensible resource filtering for application.properties and application.yml

On the last point: since the default config files accept Spring style placeholders (${…​}) the Maven filtering is changed to use @..@ placeholders (you can override that with a Maven property resource.delimiter).
最后一点,由于默认配置文件接受Spring格式的占位符,Maven过滤器被改成使用@..@占位符。你也可以通过重写resource.delimiter文件来修改

13.2.1 Inheriting the starter parent
To configure your project to inherit from the spring-boot-starter-parent simply set the parent:

<!-- Inherit defaults from Spring Boot -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

With that setup, you can also override individual dependencies by overriding a property in your own project. For instance, to upgrade to another Spring Data release train you’d add the following to your pom.xml.

<properties>
    <spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
</properties>

13.2.2 Using Spring Boot without the parent POM
Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use, or you may just prefer to explicitly declare all your Maven configuration.
不是所有人都喜欢继承来自spring-boot-starter-parent 的POM信息。

If you don’t want to use the spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency:
通过使用scope=import依赖,即使不使用spring-boot-starter-parent,你仍然可以保持依赖管理的好处(但不包括插件管理)

<dependencyManagement>
     <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.3.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

你可能感兴趣的:(spring)