diff --git a/I. Spring Boot Documentation/1. About the Documentation.md b/I. Spring Boot Documentation/1. About the Documentation.md
new file mode 100644
index 00000000..9fe5a9e8
--- /dev/null
+++ b/I. Spring Boot Documentation/1. About the Documentation.md
@@ -0,0 +1,10 @@
+### 1. 关于本文档
+
+Spring Boot参考指南有如下形式的文档:
+- [HTML](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/html)
+- [PDF](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/pdf/spring-boot-reference.pdf)
+- [EPUB](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/epub/spring-boot-reference.epub)
+
+你可以从[docs.spring.io/spring-boot/docs/current/reference](https://docs.spring.io/spring-boot/docs/current/reference)获取到最新版本。
+
+对本文档的拷贝,不管是电子版还是打印,在保证包含版权声明,并且不收取任何费用的情况下,你可以自由使用,或分发给其他人。
diff --git a/I. Spring Boot Documentation/1. About the documentation.md b/I. Spring Boot Documentation/1. About the documentation.md
deleted file mode 100644
index 16fa22e1..00000000
--- a/I. Spring Boot Documentation/1. About the documentation.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 1. 关于本文档
-
-Spring Boot参考指南有[html](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/html),[pdf](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/pdf/spring-boot-reference.pdf)和[epub](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/epub/spring-boot-reference.epub)等形式的文档,你可以从[docs.spring.io/spring-boot/docs/current/reference](http://docs.spring.io/spring-boot/docs/current/reference)获取到最新版本。
-
-对本文档的拷贝,不管是电子版还是打印,在保证包含版权声明,并且不收取任何费用的情况下,你可以自由使用,或分发给其他人。
diff --git a/I. Spring Boot Documentation/2. Getting Help.md b/I. Spring Boot Documentation/2. Getting Help.md
new file mode 100644
index 00000000..391bcfe7
--- /dev/null
+++ b/I. Spring Boot Documentation/2. Getting Help.md
@@ -0,0 +1,10 @@
+### 2. 获取帮助
+
+如果你在使用Spring Boot时遇到了麻烦,我们很乐意帮忙。
+
+- 尝试[How-to文档](../IX. ‘How-to’ guides/README.md)。它们为多数常见问题提供解决方案。
+- 学习Spring基础知识。Spring Boot是在很多其他Spring项目上构建的,查看[spring.io](http://spring.io/)站点可以获取丰富的参考文档。如果你刚开始使用Spring,可以尝试这些[指导](http://spring.io/guides)中的一个。
+- 提问题。我们时刻监控着[stackoverflow.com](http://stackoverflow.com/)上标记为[spring-boot](http://stackoverflow.com/tags/spring-boot)的问题。
+- 在[github.com/spring-projects/spring-boot/issues](https://github.com/spring-projects/spring-boot/issues)上报告Spring Boot的bug。
+
+**注**:Spring Boot的一切都是开源的,包括文档。如果你发现文档有问题,或是想提高它们的质量,请[参与进来](http://github.com/spring-projects/spring-boot/tree/master)!
diff --git a/I. Spring Boot Documentation/2. Getting help.md b/I. Spring Boot Documentation/2. Getting help.md
deleted file mode 100644
index 84e69fdb..00000000
--- a/I. Spring Boot Documentation/2. Getting help.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 2. 获取帮助
-
-使用Spring Boot遇到麻烦,我们很乐意帮忙!
-
-- 尝试[How-to’s](../IX. ‘How-to’ guides/README.md)-它们为多数常见问题提供解决方案。
-- 学习Spring基础知识-Spring Boot是在很多其他Spring项目上构建的,查看[spring.io](http://spring.io/)站点可以获取丰富的参考文档。如果你刚开始使用Spring,可以尝试这些[指导](http://spring.io/guides)中的一个。
-- 提问题-我们时刻监控着[stackoverflow.com](http://stackoverflow.com/)上标记为[spring-boot](http://stackoverflow.com/tags/spring-boot)的问题。
-- 在[github.com/spring-projects/spring-boot/issues](https://github.com/spring-projects/spring-boot/issues)上报告Spring Boot的bug。
-
-**注**:Spring Boot的一切都是开源的,包括文档!如果你发现文档有问题,或只是想提高它们的质量,请[参与进来](http://github.com/spring-projects/spring-boot/tree/master)!
diff --git a/I. Spring Boot Documentation/3. First Steps.md b/I. Spring Boot Documentation/3. First Steps.md
new file mode 100644
index 00000000..a6e64eb8
--- /dev/null
+++ b/I. Spring Boot Documentation/3. First Steps.md
@@ -0,0 +1,7 @@
+### 3. 第一步
+
+如果你想对Spring Boot或Spring有个整体认识,可以从[下列主题](../II. Getting started/README.md)开始:
+
+- 从零开始:[概述](../II. Getting started/8. Introducing Spring Boot.md)|[要求](../II. Getting started/9. System Requirements.md)|[安装](../II. Getting started/10. Installing Spring Boot.md)
+- 教程:[第一部分](../II. Getting started/11. Developing your first Spring Boot application.md)|[第二部分](../II. Getting started/11.3. Writing the code.md)
+- 运行示例:[第一部分](../II. Getting started/11.4. Running the example.md)|[第二部分](../II. Getting started/11.5. Creating an executable jar.md)
diff --git a/I. Spring Boot Documentation/3. First steps.md b/I. Spring Boot Documentation/3. First steps.md
deleted file mode 100644
index 97447527..00000000
--- a/I. Spring Boot Documentation/3. First steps.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 3. 第一步
-
-如果你想对Spring Boot或Spring有个整体认识,可以从[这里开始](../II. Getting started/README.md)!
-
-- 从零开始:[概述](../II. Getting started/8. Introducing Spring Boot.md)|[要求](../II. Getting started/9. System Requirements.md)|[安装](../II. Getting started/10. Installing Spring Boot.md)
-- 教程:[第一部分](../II. Getting started/11. Developing your first Spring Boot application.md)|[第二部分](../II. Getting started/11.3. Writing the code.md)
-- 运行示例:[第一部分](../II. Getting started/11.4. Running the example.md)|[第二部分](../II. Getting started/11.5. Creating an executable jar.md)
diff --git a/I. Spring Boot Documentation/4. Working with Spring Boot.md b/I. Spring Boot Documentation/4. Working with Spring Boot.md
index fb4cbc7f..eb00bdf1 100644
--- a/I. Spring Boot Documentation/4. Working with Spring Boot.md
+++ b/I. Spring Boot Documentation/4. Working with Spring Boot.md
@@ -1,6 +1,6 @@
### 4. 使用Spring Boot
-准备好使用Spring Boot了?[我们已经为你铺好道路](../III. Using Spring Boot/README.md).
+准备好使用Spring Boot了?[我们已经为你铺好了道路](../III. Using Spring Boot/README.md):
- 构建系统:[Maven](../III. Using Spring Boot/13.2. Maven.md)|[Gradle](../III. Using Spring Boot/13.3. Gradle.md)|[Ant](../III. Using Spring Boot/13.4. Ant.md)|[Starters](../III. Using Spring Boot/13.5. Starters.md)
- 最佳实践:[代码结构](../III. Using Spring Boot/14. Structuring your code.md)|[@Configuration](../III. Using Spring Boot/15. Configuration classes.md)|[@EnableAutoConfiguration](../III. Using Spring Boot/16. Auto-configuration.md)|[Beans和依赖注入](../III. Using Spring Boot/17. Spring Beans and dependency injection.md)
diff --git a/I. Spring Boot Documentation/5. Learning about Spring Boot Features.md b/I. Spring Boot Documentation/5. Learning about Spring Boot Features.md
new file mode 100644
index 00000000..de397edb
--- /dev/null
+++ b/I. Spring Boot Documentation/5. Learning about Spring Boot Features.md
@@ -0,0 +1,10 @@
+### 5. 了解Spring Boot特性
+
+想要了解更多Spring Boot核心特性的详情?[下列内容就是为你准备的](../IV. Spring Boot features/README.md):
+
+- 核心特性:[SpringApplication](../IV. Spring Boot features/23. SpringApplication.md)|[外部化配置](../IV. Spring Boot features/24. Externalized Configuration.md)|[Profiles](../IV. Spring Boot features/25. Profiles.md)|[日志](../IV. Spring Boot features/26. Logging.md)
+- Web应用:[MVC](../IV. Spring Boot features/27.1. The ‘Spring Web MVC framework’.md)|[内嵌容器](../IV. Spring Boot features/27.3 Embedded servlet container support.md)
+- 使用数据:[SQL](../IV. Spring Boot features/29. Working with SQL databases.md)|[NO-SQL](../IV. Spring Boot features/30. Working with NoSQL technologies.md)
+- 消息:[概述](../IV. Spring Boot features/32. Messaging.md)|[JMS](../IV. Spring Boot features/32.1. JMS.md)
+- 测试:[概述](../IV. Spring Boot features/40. Testing.md)|[Boot应用](../IV. Spring Boot features/40.3 Testing Spring Boot applications.md)|[工具](../IV. Spring Boot features/40.4 Test utilities.md)
+- 扩展:[Auto-configuration](../IV. Spring Boot features/43. Creating your own auto-configuration.md)|[@Conditions](../IV. Spring Boot features/43.3 Condition annotations.md)
diff --git a/I. Spring Boot Documentation/5. Learning about Spring Boot features.md b/I. Spring Boot Documentation/5. Learning about Spring Boot features.md
deleted file mode 100644
index ed6c3005..00000000
--- a/I. Spring Boot Documentation/5. Learning about Spring Boot features.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 5. 了解Spring Boot特性
-
-想要了解更多Spring Boot核心特性的详情?[这就是为你准备的](../IV. Spring Boot features/README.md)!
-
-- 核心特性:[SpringApplication](../IV. Spring Boot features/23. SpringApplication.md)|[外部化配置](../IV. Spring Boot features/24. Externalized Configuration.md)|[Profiles](../IV. Spring Boot features/25. Profiles.md)|[日志](../IV. Spring Boot features/26. Logging.md)
-- Web应用:[MVC](../IV. Spring Boot features/27.1. The ‘Spring Web MVC framework’.md)|[内嵌容器](../IV. Spring Boot features/27.3 Embedded servlet container support.md)
-- 使用数据:[SQL](../IV. Spring Boot features/29. Working with SQL databases.md)|[NO-SQL](../IV. Spring Boot features/30. Working with NoSQL technologies.md)
-- 消息:[概述](../IV. Spring Boot features/32. Messaging.md)|[JMS](../IV. Spring Boot features/32.1. JMS.md)
-- 测试:[概述](../IV. Spring Boot features/40. Testing.md)|[Boot应用](../IV. Spring Boot features/40.3 Testing Spring Boot applications.md)|[工具](../IV. Spring Boot features/40.4 Test utilities.md)
-- 扩展:[Auto-configuration](../IV. Spring Boot features/43. Creating your own auto-configuration.md)|[@Conditions](../IV. Spring Boot features/43.3 Condition annotations.md)
diff --git a/I. Spring Boot Documentation/6. Moving to Production.md b/I. Spring Boot Documentation/6. Moving to Production.md
new file mode 100644
index 00000000..4ea50fa4
--- /dev/null
+++ b/I. Spring Boot Documentation/6. Moving to Production.md
@@ -0,0 +1,7 @@
+### 6. 迁移到生产环境
+
+当你准备将Spring Boot应用发布到生产环境时,我们提供了一些你[可能喜欢的技巧](../V. Spring Boot Actuator/README.md)!
+
+- 管理端点:[概述](../V. Spring Boot Actuator/46. Endpoints.md)|[自定义](../V. Spring Boot Actuator/46.1 Customizing endpoints.md)
+- 连接选项:[HTTP](../V. Spring Boot Actuator/47. Monitoring and management over HTTP.md)|[JMX](../V. Spring Boot Actuator/48. Monitoring and management over JMX.md)
+- 监控:[指标](../V. Spring Boot Actuator/50. Metrics.md)|[审计](../V. Spring Boot Actuator/51. Auditing.md)|[追踪](../V. Spring Boot Actuator/52. Tracing.md)|[进程](../V. Spring Boot Actuator/53. Process monitoring.md)
diff --git a/I. Spring Boot Documentation/6. Moving to production.md b/I. Spring Boot Documentation/6. Moving to production.md
deleted file mode 100644
index 418a25c6..00000000
--- a/I. Spring Boot Documentation/6. Moving to production.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 6. 迁移到生产环境
-
-当你准备将Spring Boot应用发布到生产环境时,我们提供了一些你[可能喜欢的技巧](../V. Spring Boot Actuator/README.md)!
-
-- 管理端点:[概述](../V. Spring Boot Actuator/46. Endpoints.md)|[自定义](../V. Spring Boot Actuator/46.1 Customizing endpoints.md)
-- 连接选项:[HTTP](../V. Spring Boot Actuator/47. Monitoring and management over HTTP.md)|[JMX](../V. Spring Boot Actuator/48. Monitoring and management over JMX.md)|[SSH](../V. Spring Boot Actuator/49. Monitoring and management using a remote shell.md)
-- 监控:[指标](../V. Spring Boot Actuator/50. Metrics.md)|[审计](../V. Spring Boot Actuator/51. Auditing.md)|[追踪](../V. Spring Boot Actuator/52. Tracing.md)|[进程](../V. Spring Boot Actuator/53. Process monitoring.md)
diff --git a/I. Spring Boot Documentation/7. Advanced Topics.md b/I. Spring Boot Documentation/7. Advanced Topics.md
new file mode 100644
index 00000000..5012fdb5
--- /dev/null
+++ b/I. Spring Boot Documentation/7. Advanced Topics.md
@@ -0,0 +1,7 @@
+### 7. 高级主题
+
+最后,我们为高级用户准备了一些主题。
+
+- Spring Boot应用部署:[云部署](../VI. Deploying Spring Boot applications/55. Deploying to the cloud.md) | [操作系统服务](../VI. Deploying Spring Boot applications/56.1 Unix&Linux services.md)
+- 构建工具插件:[Maven](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-maven-plugin)|[Gradle](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-gradle-plugin)
+- 附录:[应用属性](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-application-properties)|[Auto-configuration类](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#auto-configuration-classes)|[可执行Jars](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar)
diff --git a/I. Spring Boot Documentation/7. Advanced topics.md b/I. Spring Boot Documentation/7. Advanced topics.md
deleted file mode 100644
index 1c0e08b0..00000000
--- a/I. Spring Boot Documentation/7. Advanced topics.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 7. 高级主题
-
-最后,我们为高级用户准备了一些主题。
-
-- 部署Spring Boot应用:[云部署](../VI. Deploying Spring Boot applications/55. Deploying to the cloud.md) | [操作系统服务](../VI. Deploying Spring Boot applications/56.1 Unix&Linux services.md)
-- 构建工具插件:[Maven](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-maven-plugin)|[Gradle](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-gradle-plugin)
-- 附录:[应用属性](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#common-application-properties)|[Auto-configuration类](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#auto-configuration-classes)|[可执行Jars](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#executable-jar)
diff --git a/II. Getting Started/10. Installing Spring Boot.md b/II. Getting Started/10. Installing Spring Boot.md
new file mode 100644
index 00000000..27e8dbf3
--- /dev/null
+++ b/II. Getting Started/10. Installing Spring Boot.md
@@ -0,0 +1,7 @@
+### 10. Spring Boot安装
+
+Spring Boot可以跟经典的Java开发工具一起使用或安装成一个命令行工具。无论哪种方式,你都需要安装[Java SDK v1.8 ](http://www.java.com/)或更高版本。在开始之前,你需要使用下面的命令,检查下当前安装的Java版本:
+```shell
+$ java -version
+```
+如果你是一个Java新手,或想体验一下Spring Boot,你可能想先尝试[Spring Boot CLI](10.2. Installing the Spring Boot CLI.md)(命令行界面)。否则,请继续阅读“经典”的安装指南。
\ No newline at end of file
diff --git a/II. Getting started/10.1. Installation instructions for the Java developer.md b/II. Getting Started/10.1. Installation Instructions for the Java Developer.md
similarity index 100%
rename from II. Getting started/10.1. Installation instructions for the Java developer.md
rename to II. Getting Started/10.1. Installation Instructions for the Java Developer.md
diff --git a/II. Getting Started/10.1.1. Maven Installation.md b/II. Getting Started/10.1.1. Maven Installation.md
new file mode 100644
index 00000000..c2b0e09b
--- /dev/null
+++ b/II. Getting Started/10.1.1. Maven Installation.md
@@ -0,0 +1,48 @@
+
+### 10.1.1. Maven安装
+
+Spring Boot兼容Apache Maven 3.2或更高版本。如果本地没有安装Maven,你可以参考[maven.apache.org](http://maven.apache.org/)上的指南。
+
+**注**:在很多操作系统上,可以通过包管理器来安装Maven。如果你使用OSX Homebrew,尝试`brew install maven`。Ubuntu用户可以运行`sudo apt-get install maven`。使用Chocolatey的Windows用户可以以管理员身份在命令提示符上运行`choco install maven`。
+
+Spring Boot依赖使用的groupId为`org.springframework.boot`。通常,你的Maven POM文件会继承`spring-boot-starter-parent`工程,并声明一个或多个[“Starter POMs”](../III. Using Spring Boot/13.4. Starter POMs.md)依赖。此外,Spring Boot提供了一个可选的[Maven插件](../VIII. Build tool plugins/58. Spring Boot Maven plugin.md),用于创建可执行jars。
+
+下面是一个典型的pom.xml文件:
+```xml
+
+
+ 4.0.0
+
+ com.example
+ myproject
+ 0.0.1-SNAPSHOT
+
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+```
+**注**:`spring-boot-starter-parent`是使用Spring Boot的一种不错的方式,但它并不总是最合适的。有时你可能需要继承一个不同的父POM,或是不喜欢我们的默认配置。这些情况,请查看[章节 13.2.2,在不使用parent POM的情况下玩转Spring Boot](../III. Using Spring Boot/13.1.2. Using Spring Boot without the Parent POM.md)。
diff --git a/II. Getting Started/10.1.2. Gradle Installation.md b/II. Getting Started/10.1.2. Gradle Installation.md
new file mode 100644
index 00000000..7003c6ea
--- /dev/null
+++ b/II. Getting Started/10.1.2. Gradle Installation.md
@@ -0,0 +1,32 @@
+### 10.1.2. Gradle安装
+
+Spring Boot兼容Gradle 4。如果本地没有安装Gradle,你可以参考[gradle.org](https://gradle.org/)上的指南。
+
+Spring Boot的依赖可通过groupId `org.springframework.boot`来声明。通常,你的项目声明一个或多个[“Starter POMs”](../III. Using Spring Boot/13.4. Starter POMs.md)依赖。Spring Boot提供了一个很有用的[Gradle插件](../VIII. Build tool plugins/59. Spring Boot Gradle plugin.md),可以用来简化依赖声明,创建可执行jars。
+
+**Gradle Wrapper**
+
+**注** 当你需要构建项目时,Gradle Wrapper提供一种给力的获取Gradle的方式。它是一小段脚本和库,跟你的代码一块提交,用于启动构建进程,具体参考[Gradle Wrapper](https://docs.gradle.org/4.2.1/userguide/gradle_wrapper.html)。
+
+下面是一个典型的`build.gradle`文件:
+```gradle
+plugins {
+ id 'org.springframework.boot' version '2.0.0.RELEASE'
+ id 'java'
+}
+
+
+jar {
+ baseName = 'myproject'
+ version = '0.0.1-SNAPSHOT'
+}
+
+repositories {
+ jcenter()
+}
+
+dependencies {
+ compile("org.springframework.boot:spring-boot-starter-web")
+ testCompile("org.springframework.boot:spring-boot-starter-test")
+}
+```
diff --git a/II. Getting Started/10.2. Installing the Spring Boot CLI.md b/II. Getting Started/10.2. Installing the Spring Boot CLI.md
new file mode 100644
index 00000000..276a64ff
--- /dev/null
+++ b/II. Getting Started/10.2. Installing the Spring Boot CLI.md
@@ -0,0 +1,5 @@
+### 10.2. Spring Boot CLI安装
+
+Spring Boot CLI(命令行界面)是一个命令行工具,可用于快速搭建基于Spring的原型。它支持运行[Groovy](http://groovy.codehaus.org/)脚本,这也就意味着你可以使用类似Java的语法,但不用写很多的模板代码。
+
+Spring Boot不一定非要配合CLI使用,但它绝对是Spring应用取得进展的最快方式(你咋不飞上天呢?)。
\ No newline at end of file
diff --git a/II. Getting Started/10.2.1. Manual Installation.md b/II. Getting Started/10.2.1. Manual Installation.md
new file mode 100644
index 00000000..6f2b26c4
--- /dev/null
+++ b/II. Getting Started/10.2.1. Manual Installation.md
@@ -0,0 +1,10 @@
+### 10.2.1. 手动安装
+
+Spring CLI分发包可以从Spring软件仓库下载:
+
+1. [spring-boot-cli-2.0.0.RELEASE-bin.zip](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/2.0.0.RELEASE/spring-boot-cli-2.0.0.RELEASE-bin.zip)
+2. [spring-boot-cli-2.0.0.RELEASE-bin.tar.gz](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/2.0.0.RELEASE/spring-boot-cli-2.0.0.RELEASE-bin.tar.gz)
+
+不稳定的[snapshot分发包](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/)也可以获取到。
+
+下载完成后,解压分发包,根据存档里的[INSTALL.txt](http://raw.github.com/spring-projects/spring-boot/master/spring-boot-cli/src/main/content/INSTALL.txt)操作指南进行安装。总的来说,在`.zip`文件的`bin/`目录下会有一个spring脚本(Windows下是`spring.bat`),或使用`java -jar`运行`lib/`目录下的`.jar`文件(该脚本会帮你确保classpath被正确设置)。
diff --git a/II. Getting started/10.2.2. Installation with SDKMAN.md b/II. Getting Started/10.2.2. Installation with SDKMAN.md
similarity index 85%
rename from II. Getting started/10.2.2. Installation with SDKMAN.md
rename to II. Getting Started/10.2.2. Installation with SDKMAN.md
index 70f8e463..6fedf85b 100644
--- a/II. Getting started/10.2.2. Installation with SDKMAN.md
+++ b/II. Getting Started/10.2.2. Installation with SDKMAN.md
@@ -4,16 +4,16 @@ SDKMAN(软件开发包管理器)可以对各种各样的二进制SDK包进
```shell
$ sdk install springboot
$ spring --version
-Spring Boot v2.0.0.M5
+Spring Boot v2.0.0.RELEASE
```
如果你正在为CLI开发新的特性,并想轻松获取刚构建的版本,可以使用以下命令:
```shell
-$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.0.0.M5-bin/spring-2.0.0.M5/
+$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-2.0.0.RELEASE-bin/spring-2.0.0.RELEASE/
$ sdk default springboot dev
$ spring --version
-Spring CLI v2.0.0.M5
+Spring CLI v2.0.0.RELEASE
```
-这将会安装一个名叫dev的本地spring实例,它指向你的目标构建位置,所以每次你重新构建Spring Boot,spring都会更新为最新的。
+这将会安装一个名叫dev的本地spring实例,它指向你的目标构建位置,所以每次你重新构建Spring Boot,spring都会是最新的。
你可以通过以下命令来验证:
```shell
@@ -23,7 +23,7 @@ $ sdk ls springboot
Available Springboot Versions
================================================================================
> + dev
-* 2.0.0.M5
+* 2.0.0.RELEASE
================================================================================
+ - local version
diff --git a/II. Getting Started/10.2.3. OSX Homebrew Installation.md b/II. Getting Started/10.2.3. OSX Homebrew Installation.md
new file mode 100644
index 00000000..11361d20
--- /dev/null
+++ b/II. Getting Started/10.2.3. OSX Homebrew Installation.md
@@ -0,0 +1,10 @@
+### 10.2.3. 使用OSX Homebrew进行安装
+
+如果你的环境是Mac,并使用[Homebrew](http://brew.sh/),你可以使用下面的命令安装Spring Boot CLI:
+```shell
+$ brew tap pivotal/tap
+$ brew install springboot
+```
+Homebrew会把spring安装到`/usr/local/bin`下。
+
+**注**:如果该方案不可用,可能是因为你的brew版本太老了。你需要执行`brew update`,然后重试。
diff --git a/II. Getting Started/10.2.4. MacPorts Installation.md b/II. Getting Started/10.2.4. MacPorts Installation.md
new file mode 100644
index 00000000..dee32f39
--- /dev/null
+++ b/II. Getting Started/10.2.4. MacPorts Installation.md
@@ -0,0 +1,6 @@
+### 10.2.4. 使用MacPorts进行安装
+
+如果你的环境是Mac,并使用[MacPorts](http://www.macports.org/),你可以使用下面的命令安装Spring Boot CLI:
+```shell
+$ sudo port install spring-boot-cli
+```
diff --git a/II. Getting started/10.2.5. Command-line completion.md b/II. Getting Started/10.2.5. Command-line Completion.md
similarity index 100%
rename from II. Getting started/10.2.5. Command-line completion.md
rename to II. Getting Started/10.2.5. Command-line Completion.md
diff --git a/II. Getting Started/10.2.6. Quick-start Spring CLI Example.md b/II. Getting Started/10.2.6. Quick-start Spring CLI Example.md
new file mode 100644
index 00000000..5a2855cc
--- /dev/null
+++ b/II. Getting Started/10.2.6. Quick-start Spring CLI Example.md
@@ -0,0 +1,24 @@
+### 10.2.6. Spring CLI示例快速入门
+
+你可以使用下面的web应用,测试Spring CLI安装是否成功。创建一个名叫`app.groovy`的文件:
+```groovy
+@RestController
+class ThisWillActuallyRun {
+
+ @RequestMapping("/")
+ String home() {
+ "Hello World!"
+ }
+
+}
+```
+然后,在shell中运行以下命令:
+```shell
+$ spring run app.groovy
+```
+**注**:首次运行该应用比较慢,因为需要下载依赖,后续运行将会快很多。
+
+使用你最喜欢的浏览器打开[localhost:8080](localhost:8080),然后就可以看到如下输出:
+```java
+Hello World!
+```
diff --git a/II. Getting Started/10.3. Upgrading from an Earlier Version of Spring Boot.md b/II. Getting Started/10.3. Upgrading from an Earlier Version of Spring Boot.md
new file mode 100644
index 00000000..7f5211ee
--- /dev/null
+++ b/II. Getting Started/10.3. Upgrading from an Earlier Version of Spring Boot.md
@@ -0,0 +1,5 @@
+### 10.3. 版本升级
+
+如果你正在升级Spring Boot的早期发布版本,那最好查看下[project wiki](http://github.com/spring-projects/spring-boot/wiki)上的"迁移指南",你会找到升级说明和一个对应每次版本发布的"new and noteworthy"特性列表。
+
+想要升级一个已安装的CLI,你需要使用合适的包管理命令,例如`brew upgrade`;如果是手动安装CLI,按照[standard instructions](10.2.1. Manual installation.md)操作并记得更新你的PATH环境变量以移除任何老的引用。
diff --git a/II. Getting Started/11. Developing Your First Spring Boot Application.md b/II. Getting Started/11. Developing Your First Spring Boot Application.md
new file mode 100644
index 00000000..c5858388
--- /dev/null
+++ b/II. Getting Started/11. Developing Your First Spring Boot Application.md
@@ -0,0 +1,19 @@
+### 11. 开发你的第一个Spring Boot应用
+
+这一节描述怎样开发一个简单的"Hello World" web应用,以此强调下Spring Boot的一些关键特性。项目采用Maven进行构建,因为大多数IDE都支持它。
+
+**注**:[spring.io](http://spring.io/)网站包含很多Spring Boot"入门"指南,如果你需要特定问题的解决方案,可以先去那瞅瞅。你也可以简化下面的步骤,直接从[start.spring.io](https://start.spring.io/)的依赖搜索器选中`Web` starter,这会生成一个新的项目结构,然后你就可以happy的敲代码了。具体详情参考[文档](https://github.com/spring-io/initializr)。
+
+在开始前,你需要打开终端运行以下命令,确保已经安装好了可用的Java和Maven版本:
+```shell
+$ java -version
+java version "1.8.0_102"
+Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
+Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
+```
+```shell
+$ mvn -v
+Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
+Maven home: /usr/local/Cellar/maven/3.3.9/libexec Java version: 1.8.0_102, vendor: Oracle Corporation
+```
+**注**:该示例需要创建单独的文件夹,后续的操作建立在你已创建一个合适的文件夹,并且它是你的当前目录。
diff --git a/II. Getting Started/11.1. Creating the POM.md b/II. Getting Started/11.1. Creating the POM.md
new file mode 100644
index 00000000..bc26dc95
--- /dev/null
+++ b/II. Getting Started/11.1. Creating the POM.md
@@ -0,0 +1,26 @@
+### 11.1. 创建POM
+
+让我们以创建一个Maven `pom.xml`文件作为开始吧,因为`pom.xml`是构建项目的处方!打开你最喜欢的文本编辑器,并添加以下内容:
+```xml
+
+
+ 4.0.0
+
+ com.example
+ myproject
+ 0.0.1-SNAPSHOT
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+
+
+
+
+```
+这样一个可工作的构建就完成了,你可以通过运行`mvn package`测试它(暂时忽略"jar将是空的-没有包含任何内容!"的警告)。
+
+**注**:此刻,你可以将该项目导入到IDE中(大多数现代的Java IDE都包含对Maven的内建支持)。简单起见,我们继续使用普通的文本编辑器完成该示例。
\ No newline at end of file
diff --git a/II. Getting Started/11.2. Adding Classpath Dependencies.md b/II. Getting Started/11.2. Adding Classpath Dependencies.md
new file mode 100644
index 00000000..06743854
--- /dev/null
+++ b/II. Getting Started/11.2. Adding Classpath Dependencies.md
@@ -0,0 +1,19 @@
+### 11.2. 添加classpath依赖
+
+Spring Boot提供很多"Starters",用来简化添加jars到classpath的操作。示例程序中已经在POM的`parent`节点使用了`spring-boot-starter-parent`,它是一个特殊的starter,提供了有用的Maven默认设置。同时,它也提供一个`dependency-management`节点,这样对于期望(”blessed“)的依赖就可以省略version标记了。
+
+其他”Starters“提供开发特定类型应用所需的依赖。由于正在开发web应用,我们添加`spring-boot-starter-web`依赖。在此之前,我们可以运行下面的命令,先看一下目前的依赖:
+```shell
+$ mvn dependency:tree
+[INFO] com.example:myproject:jar:0.0.1-SNAPSHOT
+```
+`mvn dependency:tree`命令可以将项目依赖以树形方式展现出来,你可以看到`spring-boot-starter-parent`本身并没有提供依赖。为了添加需要的依赖,编辑你的`pom.xml`,并在`parent`节点下添加`spring-boot-starter-web`依赖:
+```xml
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+```
+如果再次运行`mvn dependency:tree`,你将看到现在多了一些其他依赖,包括Tomcat web服务器和Spring Boot自身。
diff --git a/II. Getting Started/11.3. Writing the Code.md b/II. Getting Started/11.3. Writing the Code.md
new file mode 100644
index 00000000..061b09f2
--- /dev/null
+++ b/II. Getting Started/11.3. Writing the Code.md
@@ -0,0 +1,24 @@
+### 11.3. 编写代码
+
+为了完成应用程序,我们需要创建一个单独的Java文件。默认地,Maven会编译`src/main/java`下的源码,所以你需要创建那样的文件结构,然后添加一个名为`src/main/java/Example.java`的文件:
+```java
+import org.springframework.boot.*;
+import org.springframework.boot.autoconfigure.*;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@EnableAutoConfiguration
+public class Example {
+
+ @RequestMapping("/")
+ String home() {
+ return "Hello World!";
+ }
+
+ public static void main(String[] args) throws Exception {
+ SpringApplication.run(Example.class, args);
+ }
+
+}
+```
+尽管代码不多,但已经发生了很多事情。我们在接下来的几节里分步探讨重要的部分。
diff --git a/II. Getting Started/11.3.1. The @RestController and @RequestMapping Annotations.md b/II. Getting Started/11.3.1. The @RestController and @RequestMapping Annotations.md
new file mode 100644
index 00000000..687a9726
--- /dev/null
+++ b/II. Getting Started/11.3.1. The @RestController and @RequestMapping Annotations.md
@@ -0,0 +1,8 @@
+
+### 11.3.1. @RestController和@RequestMapping注解
+
+Example类上使用的第一个注解是`@RestController`,这被称为构造型(stereotype)注解。它为阅读代码的人提供暗示(这是一个支持REST的控制器),对于Spring,该类扮演了一个特殊角色。在本示例中,我们的类是一个web `@Controller`,所以当web请求进来时,Spring会考虑是否使用它来处理。
+
+`@RequestMapping`注解提供路由信息,它告诉Spring任何来自/路径的HTTP请求都应该被映射到`home`方法。`@RestController`注解告诉Spring以字符串的形式渲染结果,并直接返回给调用者。
+
+**注**:`@RestController`和`@RequestMapping`是Spring MVC中的注解(它们不是Spring Boot的特定部分)。具体参考Spring文档的[MVC章节](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#mvc)。
diff --git a/II. Getting Started/11.3.2. The @EnableAutoConfiguration Annotation.md b/II. Getting Started/11.3.2. The @EnableAutoConfiguration Annotation.md
new file mode 100644
index 00000000..6451ae85
--- /dev/null
+++ b/II. Getting Started/11.3.2. The @EnableAutoConfiguration Annotation.md
@@ -0,0 +1,5 @@
+### 11.3.2. @EnableAutoConfiguration注解
+
+第二个类级别的注解是`@EnableAutoConfiguration`,这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于`spring-boot-starter-web`添加了Tomcat和Spring MVC,所以auto-configuration假定你正在开发一个web应用,并对Spring进行相应地设置。
+
+**Starters和Auto-Configuration**:Auto-configuration设计成可以跟"Starters"一起很好的使用,但这两个概念没有直接的联系。你可以自由地挑选starters以外的jar依赖,Spring Boot仍会尽最大努力去自动配置你的应用。
diff --git "a/II. Getting started/11.3.3. The \342\200\234main\342\200\235 method.md" "b/II. Getting Started/11.3.3. The \342\200\234main\342\200\235 Method.md"
similarity index 100%
rename from "II. Getting started/11.3.3. The \342\200\234main\342\200\235 method.md"
rename to "II. Getting Started/11.3.3. The \342\200\234main\342\200\235 Method.md"
diff --git a/II. Getting Started/11.4. Running the Example.md b/II. Getting Started/11.4. Running the Example.md
new file mode 100644
index 00000000..e8e20a76
--- /dev/null
+++ b/II. Getting Started/11.4. Running the Example.md
@@ -0,0 +1,23 @@
+### 11.4. 运行示例
+
+到此,示例应用可以工作了。由于使用了`spring-boot-starter-parent` POM,这样你就有了一个非常有用的run目标来启动程序。在项目根目录下输入`mvn spring-boot:run`启动应用。你会看到如下的输出:
+```shell
+$ mvn spring-boot:run
+
+ . ____ _ __ _ _
+ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
+( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
+ \\/ ___)| |_)| | | | | || (_| | ) ) ) )
+ ' |____| .__|_| |_|_| |_\__, | / / / /
+ =========|_|==============|___/=/_/_/_/
+ :: Spring Boot :: (v2.0.0.RELEASE)
+....... . . .
+....... . . . (log output here)
+....... . . .
+........ Started Example in 2.222 seconds (JVM running for 6.514)
+```
+如果使用浏览器打开[localhost:8080](http://localhost:8080),你应该可以看到如下输出:
+```shell
+Hello World!
+```
+点击`ctrl-c`温柔地关闭应用程序。
diff --git a/II. Getting Started/11.5. Creating an Executable Jar.md b/II. Getting Started/11.5. Creating an Executable Jar.md
new file mode 100644
index 00000000..4406f4ec
--- /dev/null
+++ b/II. Getting Started/11.5. Creating an Executable Jar.md
@@ -0,0 +1,60 @@
+### 11.5. 创建可执行jar
+
+我们通过创建一个完全自包含,并可以在生产环境运行的可执行jar来结束示例。可执行jars(有时被称为胖jars "fat jars")是包含编译后的类及代码运行所需依赖jar的存档。
+
+**可执行jars和Java**:Java没有提供一个标准方式,用于加载内嵌jar文件(即jar文件中还包含jar文件),这对分发自包含应用来说是个问题。为了解决该问题,很多开发者采用"共享的"jars。共享的jar只是将所有应用依赖的类打包进一个单独的存档,这种方式存在的问题是,很难区分应用程序中使用了哪些库。在多个jars中如果存在相同的文件名(但内容不一样)也会是一个问题。Spring Boot采取一个[不同的方式](../X. Appendices/D. The executable jar format.md),让你真正的直接内嵌jars。
+
+为了创建可执行的jar,我们需要将`spring-boot-maven-plugin`添加到`pom.xml`中,在dependencies节点后面插入以下内容:
+```xml
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+```
+**注**:`spring-boot-starter-parent` POM包含绑定到repackage目标的``配置。如果不使用parent POM,你需要自己声明该配置,具体参考[插件文档](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/maven-plugin/usage.html)。
+
+保存`pom.xml`,并从命令行运行`mvn package`:
+```shell
+$ mvn package
+
+[INFO] Scanning for projects...
+[INFO]
+[INFO] ------------------------------------------------------------------------
+[INFO] Building myproject 0.0.1-SNAPSHOT
+[INFO] ------------------------------------------------------------------------
+[INFO] .... ..
+[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject ---
+[INFO] Building jar: /Users/developer/example/spring-boot-example/target/myproject-0.0.1-SNAPSHOT.jar
+[INFO]
+[INFO] --- spring-boot-maven-plugin:2.0.0.RELEASE:repackage (default) @ myproject ---
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD SUCCESS
+[INFO] ------------------------------------------------------------------------
+```
+如果查看target目录,你应该可以看到`myproject-0.0.1-SNAPSHOT.jar`,该文件大概有10MB。想查看内部结构,可以运行`jar tvf`:
+```shell
+$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
+```
+在该目录下,你应该还能看到一个很小的名为`myproject-0.0.1-SNAPSHOT.jar.original`的文件,这是在Spring Boot重新打包前,Maven创建的原始jar文件。
+
+可以使用`java -jar`命令运行该应用程序:
+```shell
+$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
+
+ . ____ _ __ _ _
+ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
+( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
+ \\/ ___)| |_)| | | | | || (_| | ) ) ) )
+ ' |____| .__|_| |_|_| |_\__, | / / / /
+ =========|_|==============|___/=/_/_/_/
+ :: Spring Boot :: (v2.0.0.RELEASE)
+....... . . .
+....... . . . (log output here)
+....... . . .
+........ Started Example in 2.536 seconds (JVM running for 2.864)
+```
+如前所述,点击`ctrl-c`退出应用。
diff --git a/II. Getting Started/12. What to Read Next.md b/II. Getting Started/12. What to Read Next.md
new file mode 100644
index 00000000..5855d166
--- /dev/null
+++ b/II. Getting Started/12. What to Read Next.md
@@ -0,0 +1,7 @@
+### 12. 接下来阅读什么
+
+希望本章节已提供一些Spring Boot的基础部分,并帮你找到开发自己应用的方式。如果你是任务驱动型的开发者,那可以直接跳到[spring.io](http://spring.io/),check out一些[入门指南](http://spring.io/guides/),以解决特定的"使用Spring如何做"的问题;我们也有Spring Boot相关的[How-to](../IX. ‘How-to’ guides/README.md)参考文档。
+
+[Spring Boot仓库](http://github.com/spring-projects/spring-boot)有大量可以运行的[示例](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples),这些示例代码是彼此独立的(运行或使用示例的时候不需要构建其他示例)。
+
+否则,下一步就是阅读 [III、使用Spring Boot](../III. Using Spring Boot/README.md),如果没耐心,可以跳过该章节,直接阅读 [IV、Spring Boot特性](../IV. Spring Boot features/README.md)。
diff --git a/II. Getting started/8. Introducing Spring Boot.md b/II. Getting Started/8. Introducing Spring Boot.md
similarity index 84%
rename from II. Getting started/8. Introducing Spring Boot.md
rename to II. Getting Started/8. Introducing Spring Boot.md
index c4887606..1e336116 100644
--- a/II. Getting started/8. Introducing Spring Boot.md
+++ b/II. Getting Started/8. Introducing Spring Boot.md
@@ -1,6 +1,6 @@
### 8. Spring Boot介绍
-Spring Boot简化了基于Spring的应用开发,你只需要"run"就能创建一个独立的,产品级别的Spring应用。
+Spring Boot简化了基于Spring的应用开发。你可以很容易地创建一个独立的,产品级别的Spring应用。
我们为Spring平台及第三方库提供开箱即用的设置,这样你就可以有条不紊地开始。多数Spring Boot应用只需要很少的Spring配置。
你可以使用Spring Boot创建Java应用,并使用`java -jar`启动它或采用传统的war部署方式。我们也提供了一个运行"spring脚本"的命令行工具。
diff --git a/II. Getting Started/9. System Requirements.md b/II. Getting Started/9. System Requirements.md
new file mode 100644
index 00000000..d04821b4
--- /dev/null
+++ b/II. Getting Started/9. System Requirements.md
@@ -0,0 +1,3 @@
+### 9. 系统要求
+
+Spring Boot 2.0.0.RELEASE 需要[Java8或者9](http://www.java.com/)环境,Spring框架[5.0.4.RELEASE](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/)或以上版本。明确提供构建支持的有Maven 3.2+和Gradle 4。
\ No newline at end of file
diff --git a/II. Getting Started/9.1. Servlet Containers.md b/II. Getting Started/9.1. Servlet Containers.md
new file mode 100644
index 00000000..0bfcfad7
--- /dev/null
+++ b/II. Getting Started/9.1. Servlet Containers.md
@@ -0,0 +1,11 @@
+### 9.1. Servlet容器
+
+Spring Boot支持下列内嵌容器:
+
+|名称|Servlet版本|
+|--------|:-------|
+|Tomcat 8.5|3.1|
+|Jetty 9.4|3.1|
+|Undertow 1.4|3.1|
+
+你也可以将Spring Boot应用部署到任何兼容Servlet 3.0+的容器。
\ No newline at end of file
diff --git a/II. Getting Started/README.md b/II. Getting Started/README.md
new file mode 100644
index 00000000..870e6582
--- /dev/null
+++ b/II. Getting Started/README.md
@@ -0,0 +1,3 @@
+### 入门指南
+
+如果你想从大体上了解Spring Boot或Spring,本章节正是你所需要的!本节中,我们会回答基本的"what?","how?"和"why?"等问题,简单介绍下Spring Boot,并说明怎么安装。然后我们会构建第一个Spring Boot应用,并讨论一些需要遵循的核心原则。
diff --git a/II. Getting started/10. Installing Spring Boot.md b/II. Getting started/10. Installing Spring Boot.md
deleted file mode 100644
index 7cd2f981..00000000
--- a/II. Getting started/10. Installing Spring Boot.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 10. Spring Boot安装
-
-Spring Boot可以跟经典的Java开发工具(Eclipse,IntelliJ等)一起使用或安装成一个命令行工具。不管怎样,你都需要安装[Java SDK v1.8 ](http://www.java.com/)或更高版本。在开始之前,你需要检查下当前安装的Java版本:
-```shell
-$ java -version
-```
-如果你是一个Java新手,或只是想体验一下Spring Boot,你可能想先尝试[Spring Boot CLI](10.2. Installing the Spring Boot CLI.md),否则继续阅读“经典”地安装指南。
diff --git a/II. Getting started/10.1.1. Maven installation.md b/II. Getting started/10.1.1. Maven installation.md
deleted file mode 100644
index 89e6520b..00000000
--- a/II. Getting started/10.1.1. Maven installation.md
+++ /dev/null
@@ -1,71 +0,0 @@
-
-### 10.1.1. Maven安装
-
-Spring Boot兼容Apache Maven 3.2或更高版本。如果本地没有安装Maven,你可以参考[maven.apache.org](http://maven.apache.org/)上的指南。
-
-**注**:在很多操作系统上,可以通过包管理器来安装Maven。OSX Homebrew用户可以尝试`brew install maven`。Ubuntu用户可以运行`sudo apt-get install maven`。使用Chocolatey的Windows用户可以以管理员身份在命令提示符上运行`choco install maven`。
-
-Spring Boot依赖使用的groupId为`org.springframework.boot`。通常,你的Maven POM文件会继承`spring-boot-starter-parent`工程,并声明一个或多个[“Starter POMs”](../III. Using Spring Boot/13.4. Starter POMs.md)依赖。此外,Spring Boot提供了一个可选的[Maven插件](../VIII. Build tool plugins/58. Spring Boot Maven plugin.md),用于创建可执行jars。
-
-下面是一个典型的pom.xml文件:
-```xml
-
-
- 4.0.0
-
- com.example
- myproject
- 0.0.1-SNAPSHOT
-
-
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.0.0.M5
-
-
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
-
-
-
-
- spring-snapshots
- http://repo.spring.io/snapshot
- true
-
-
- spring-milestones
- http://repo.spring.io/milestone
-
-
-
-
- spring-snapshots
- http://repo.spring.io/snapshot
-
-
- spring-milestones
- http://repo.spring.io/milestone
-
-
-
-```
-**注**:`spring-boot-starter-parent`是使用Spring Boot的一种不错的方式,但它并不总是最合适的。有时你可能需要继承一个不同的父 POM,或只是不喜欢我们的默认配置,那你可以使用import作用域这种替代方案,具体查看[Section 13.2.2, “Using Spring Boot without the parent POM”](../III. Using Spring Boot/13.1.2. Using Spring Boot without the parent POM.md)。
diff --git a/II. Getting started/10.1.2. Gradle installation.md b/II. Getting started/10.1.2. Gradle installation.md
deleted file mode 100644
index f43ff5df..00000000
--- a/II. Getting started/10.1.2. Gradle installation.md
+++ /dev/null
@@ -1,42 +0,0 @@
-### 10.1.2. Gradle安装
-
-Spring Boot兼容Gradle 4。如果本地没有安装Gradle,你可以参考[www.gradle.org](http://www.gradle.org/)上的指南。
-
-Spring Boot的依赖可通过groupId `org.springframework.boot`来声明。通常,你的项目将声明一个或多个[“Starter POMs”](../III. Using Spring Boot/13.4. Starter POMs.md)依赖。Spring Boot提供了一个很有用的[Gradle插件](../VIII. Build tool plugins/59. Spring Boot Gradle plugin.md),可以用来简化依赖声明,创建可执行jars。
-
-**注** 当你需要构建项目时,Gradle Wrapper提供一种给力的获取Gradle的方式。它是一小段脚本和库,跟你的代码一块提交,用于启动构建进程,具体参考[Gradle Wrapper](https://docs.gradle.org/4.0.2/userguide/gradle_wrapper.html)。
-
-下面是一个典型的`build.gradle`文件:
-```gradle
-buildscript {
- repositories {
- jcenter()
- maven { url 'http://repo.spring.io/snapshot' }
- maven { url 'http://repo.spring.io/milestone' }
- }
- dependencies {
- classpath('org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M5')
- }
-}
-
-apply plugin: 'java'
-apply plugin: 'org.springframework.boot'
-apply plugin: 'io.spring.dependency-management'
-
-jar {
- baseName = 'myproject'
- version = '0.0.1-SNAPSHOT'
-}
-
-repositories {
- jcenter()
- maven { url "http://repo.spring.io/snapshot" }
- maven { url "http://repo.spring.io/milestone" }
-}
-
-dependencies {
- compile("org.springframework.boot:spring-boot-starter-web")
- testCompile("org.springframework.boot:spring-boot-starter-test")
-}
-
-```
diff --git a/II. Getting started/10.2. Installing the Spring Boot CLI.md b/II. Getting started/10.2. Installing the Spring Boot CLI.md
deleted file mode 100644
index 8dafc680..00000000
--- a/II. Getting started/10.2. Installing the Spring Boot CLI.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 10.2. Spring Boot CLI安装
-
-Spring Boot CLI是一个命令行工具,可用于快速搭建基于Spring的原型。它支持运行[Groovy](http://groovy.codehaus.org/)脚本,这也就意味着你可以使用类似Java的语法,但不用写很多的模板代码。
-
-Spring Boot不一定非要配合CLI使用,但它绝对是Spring应用取得进展的最快方式(你咋不飞上天呢?)。
diff --git a/II. Getting started/10.2.1. Manual installation.md b/II. Getting started/10.2.1. Manual installation.md
deleted file mode 100644
index b99c487a..00000000
--- a/II. Getting started/10.2.1. Manual installation.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 10.2.1. 手动安装
-
-Spring CLI分发包可以从Spring软件仓库下载:
-
-1. [spring-boot-cli-2.0.0.M5-bin.zip](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/2.0.0.M5/spring-boot-cli-2.0.0.M5-bin.zip)
-2. [spring-boot-cli-2.0.0.M5-bin.tar.gz](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/2.0.0.M5/spring-boot-cli-2.0.0.M5-bin.tar.gz)
-
-不稳定的[snapshot分发包](http://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/)也可以获取到。
-
-下载完成后,解压分发包,根据存档里的[INSTALL.txt](http://raw.github.com/spring-projects/spring-boot/master/spring-boot-cli/src/main/content/INSTALL.txt)操作指南进行安装。总的来说,在`.zip`文件的`bin/`目录下会有一个spring脚本(Windows下是`spring.bat`),或使用`java -jar`运行`lib/`目录下的`.jar`文件(该脚本会帮你确保classpath被正确设置)。
diff --git a/II. Getting started/10.2.3. OSX Homebrew installation.md b/II. Getting started/10.2.3. OSX Homebrew installation.md
deleted file mode 100644
index bdac8e3a..00000000
--- a/II. Getting started/10.2.3. OSX Homebrew installation.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 10.2.3. 使用OSX Homebrew进行安装
-
-如果你的环境是Mac,并使用[Homebrew](http://brew.sh/),想要安装Spring Boot CLI只需以下操作:
-```shell
-$ brew tap pivotal/tap
-$ brew install springboot
-```
-Homebrew将把spring安装到`/usr/local/bin`下。
-
-**注**:如果该方案不可用,可能是因为你的brew版本太老了。你只需执行`brew update`并重试即可。
diff --git a/II. Getting started/10.2.4. MacPorts installation.md b/II. Getting started/10.2.4. MacPorts installation.md
deleted file mode 100644
index df019ae7..00000000
--- a/II. Getting started/10.2.4. MacPorts installation.md
+++ /dev/null
@@ -1,6 +0,0 @@
-### 10.2.4. 使用MacPorts进行安装
-
-如果你的环境是Mac,并使用[MacPorts](http://www.macports.org/),想要安装Spring Boot CLI只需以下操作:
-```shell
-$ sudo port install spring-boot-cli
-```
diff --git a/II. Getting started/10.2.6. Quick start Spring CLI example.md b/II. Getting started/10.2.6. Quick start Spring CLI example.md
deleted file mode 100644
index e10a158c..00000000
--- a/II. Getting started/10.2.6. Quick start Spring CLI example.md
+++ /dev/null
@@ -1,24 +0,0 @@
-### 10.2.6. Spring CLI示例快速入门
-
-下面是一个相当简单的web应用,你可以用它测试Spring CLI安装是否成功。创建一个名叫`app.groovy`的文件:
-```groovy
-@RestController
-class ThisWillActuallyRun {
-
- @RequestMapping("/")
- String home() {
- "Hello World!"
- }
-
-}
-```
-然后只需在shell中运行以下命令:
-```shell
-$ spring run app.groovy
-```
-**注**:首次运行该应用将会花费一些时间,因为需要下载依赖,后续运行将会快很多。
-
-使用你最喜欢的浏览器打开[localhost:8080](localhost:8080),然后就可以看到如下输出:
-```java
-Hello World!
-```
diff --git a/II. Getting started/10.3. Upgrading from an earlier version of Spring Boot.md b/II. Getting started/10.3. Upgrading from an earlier version of Spring Boot.md
deleted file mode 100644
index 558844be..00000000
--- a/II. Getting started/10.3. Upgrading from an earlier version of Spring Boot.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 10.3. 版本升级
-
-如果你正在升级Spring Boot的早期发布版本,那最好查看下[project wiki](http://github.com/spring-projects/spring-boot/wiki)上的"release notes",你会发现每次发布对应的升级指南和一个"new and noteworthy"特性列表。
-
-想要升级一个已安装的CLI,你需要使用合适的包管理命令,例如`brew upgrade`;如果是手动安装CLI,按照[standard instructions](10.2.1. Manual installation.md)操作并记得更新你的PATH环境变量以移除任何老的引用。
diff --git a/II. Getting started/11. Developing your first Spring Boot application.md b/II. Getting started/11. Developing your first Spring Boot application.md
deleted file mode 100644
index a60132ea..00000000
--- a/II. Getting started/11. Developing your first Spring Boot application.md
+++ /dev/null
@@ -1,19 +0,0 @@
-### 11. 开发你的第一个Spring Boot应用
-
-我们将使用Java开发一个简单的"Hello World" web应用,以此强调下Spring Boot的一些关键特性。项目采用Maven进行构建,因为大多数IDEs都支持它。
-
-**注**:[spring.io](http://spring.io/)网站包含很多Spring Boot"入门"指南,如果你正在找特定问题的解决方案,可以先去那瞅瞅。你也可以简化下面的步骤,直接从[start.spring.io](https://start.spring.io/)的依赖搜索器选中`web` starter,这会自动生成一个新的项目结构,然后你就可以happy的敲代码了。具体详情参考[文档](https://github.com/spring-io/initializr)。
-
-在开始前,你需要打开终端检查下安装的Java和Maven版本是否可用:
-```shell
-$ java -version
-java version "1.8.0_102"
-Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
-Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
-```
-```shell
-$ mvn -v
-Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
-Maven home: /usr/local/Cellar/maven/3.3.9/libexec Java version: 1.8.0_102, vendor: Oracle Corporation
-```
-**注**:该示例需要创建单独的文件夹,后续的操作建立在你已创建一个合适的文件夹,并且它是你的“当前目录”。
diff --git a/II. Getting started/11.1. Creating the POM.md b/II. Getting started/11.1. Creating the POM.md
deleted file mode 100644
index bc69b414..00000000
--- a/II. Getting started/11.1. Creating the POM.md
+++ /dev/null
@@ -1,48 +0,0 @@
-### 11.1. 创建POM
-
-让我们以创建一个Maven `pom.xml`文件作为开始吧,因为`pom.xml`是构建项目的处方!打开你最喜欢的文本编辑器,并添加以下内容:
-```xml
-
-
- 4.0.0
-
- com.example
- myproject
- 0.0.1-SNAPSHOT
-
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.0.0.M5
-
-
-
-
-
-
-
- spring-snapshots
- http://repo.spring.io/snapshot
- true
-
-
- spring-milestones
- http://repo.spring.io/milestone
-
-
-
-
- spring-snapshots
- http://repo.spring.io/snapshot
-
-
- spring-milestones
- http://repo.spring.io/milestone
-
-
-
-```
-这样一个可工作的构建就完成了,你可以通过运行`mvn package`测试它(暂时忽略"jar将是空的-没有包含任何内容!"的警告)。
-
-**注**:此刻,你可以将该项目导入到IDE中(大多数现代的Java IDE都包含对Maven的内建支持)。简单起见,我们将继续使用普通的文本编辑器完成该示例。
diff --git a/II. Getting started/11.2. Adding classpath dependencies.md b/II. Getting started/11.2. Adding classpath dependencies.md
deleted file mode 100644
index 6919f826..00000000
--- a/II. Getting started/11.2. Adding classpath dependencies.md
+++ /dev/null
@@ -1,19 +0,0 @@
-### 11.2. 添加classpath依赖
-
-Spring Boot提供很多"Starters",用来简化添加jars到classpath的操作。示例程序中已经在POM的`parent`节点使用了`spring-boot-starter-parent`,它是一个特殊的starter,提供了有用的Maven默认设置。同时,它也提供一个`dependency-management`节点,这样对于期望(”blessed“)的依赖就可以省略version标记了。
-
-其他”Starters“只简单提供开发特定类型应用所需的依赖。由于正在开发web应用,我们将添加`spring-boot-starter-web`依赖-但在此之前,让我们先看下目前的依赖:
-```shell
-$ mvn dependency:tree
-[INFO] com.example:myproject:jar:0.0.1-SNAPSHOT
-```
-`mvn dependency:tree`命令可以将项目依赖以树形方式展现出来,你可以看到`spring-boot-starter-parent`本身并没有提供依赖。编辑`pom.xml`,并在`parent`节点下添加`spring-boot-starter-web`依赖:
-```xml
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-```
-如果再次运行`mvn dependency:tree`,你将看到现在多了一些其他依赖,包括Tomcat web服务器和Spring Boot自身。
diff --git a/II. Getting started/11.3. Writing the code.md b/II. Getting started/11.3. Writing the code.md
deleted file mode 100644
index 3bfa38a6..00000000
--- a/II. Getting started/11.3. Writing the code.md
+++ /dev/null
@@ -1,25 +0,0 @@
-### 11.3. 编写代码
-
-为了完成应用程序,我们需要创建一个单独的Java文件。Maven默认会编译`src/main/java`下的源码,所以你需要创建那样的文件结构,并添加一个名为`src/main/java/Example.java`的文件:
-```java
-import org.springframework.boot.*;
-import org.springframework.boot.autoconfigure.*;
-import org.springframework.stereotype.*;
-import org.springframework.web.bind.annotation.*;
-
-@RestController
-@EnableAutoConfiguration
-public class Example {
-
- @RequestMapping("/")
- String home() {
- return "Hello World!";
- }
-
- public static void main(String[] args) throws Exception {
- SpringApplication.run(Example.class, args);
- }
-
-}
-```
-尽管代码不多,但已经发生了很多事情,让我们分步探讨重要的部分吧!
diff --git a/II. Getting started/11.3.1. The @RestController and @RequestMapping annotations.md b/II. Getting started/11.3.1. The @RestController and @RequestMapping annotations.md
deleted file mode 100644
index 86e4cc07..00000000
--- a/II. Getting started/11.3.1. The @RestController and @RequestMapping annotations.md
+++ /dev/null
@@ -1,8 +0,0 @@
-
-### 11.3.1. @RestController和@RequestMapping注解
-
-Example类上使用的第一个注解是`@RestController`,这被称为构造型(stereotype)注解。它为阅读代码的人提供暗示(这是一个支持REST的控制器),对于Spring,该类扮演了一个特殊角色。在本示例中,我们的类是一个web `@Controller`,所以当web请求进来时,Spring会考虑是否使用它来处理。
-
-`@RequestMapping`注解提供路由信息,它告诉Spring任何来自"/"路径的HTTP请求都应该被映射到`home`方法。`@RestController`注解告诉Spring以字符串的形式渲染结果,并直接返回给调用者。
-
-**注**:`@RestController`和`@RequestMapping`是Spring MVC中的注解(它们不是Spring Boot的特定部分),具体参考Spring文档的[MVC章节](http://mvc.linesh.tw)。
diff --git a/II. Getting started/11.3.2. The @EnableAutoConfiguration annotation.md b/II. Getting started/11.3.2. The @EnableAutoConfiguration annotation.md
deleted file mode 100644
index 4e2f0ec5..00000000
--- a/II. Getting started/11.3.2. The @EnableAutoConfiguration annotation.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 11.3.2. @EnableAutoConfiguration注解
-
-第二个类级别的注解是`@EnableAutoConfiguration`,这个注解告诉Spring Boot根据添加的jar依赖猜测你想如何配置Spring。由于`spring-boot-starter-web`添加了Tomcat和Spring MVC,所以auto-configuration将假定你正在开发一个web应用,并对Spring进行相应地设置。
-
-**Starters和Auto-Configuration**:Auto-configuration设计成可以跟"Starters"一起很好的使用,但这两个概念没有直接的联系。你可以自由地挑选starters以外的jar依赖,Spring Boot仍会尽最大努力去自动配置你的应用。
diff --git a/II. Getting started/11.4. Running the example.md b/II. Getting started/11.4. Running the example.md
deleted file mode 100644
index 274abedd..00000000
--- a/II. Getting started/11.4. Running the example.md
+++ /dev/null
@@ -1,23 +0,0 @@
-### 11.4. 运行示例
-
-到此,示例应用可以工作了。由于使用了`spring-boot-starter-parent` POM,这样我们就有了一个非常有用的run目标来启动程序。在项目根目录下输入`mvn spring-boot:run`启动应用:
-```shell
-$ mvn spring-boot:run
-
- . ____ _ __ _ _
- /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
-( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
- \\/ ___)| |_)| | | | | || (_| | ) ) ) )
- ' |____| .__|_| |_|_| |_\__, | / / / /
- =========|_|==============|___/=/_/_/_/
- :: Spring Boot :: (v2.0.0.M5)
-....... . . .
-....... . . . (log output here)
-....... . . .
-........ Started Example in 2.222 seconds (JVM running for 6.514)
-```
-如果使用浏览器打开[localhost:8080](http://localhost:8080),你应该可以看到如下输出:
-```shell
-Hello World!
-```
-点击`ctrl-c`温雅地关闭应用程序。
diff --git a/II. Getting started/11.5. Creating an executable jar.md b/II. Getting started/11.5. Creating an executable jar.md
deleted file mode 100644
index 54facb2e..00000000
--- a/II. Getting started/11.5. Creating an executable jar.md
+++ /dev/null
@@ -1,60 +0,0 @@
-### 11.5. 创建可执行jar
-
-让我们通过创建一个完全自包含,并可以在生产环境运行的可执行jar来结束示例吧!可执行jars(有时被称为胖jars "fat jars")是包含编译后的类及代码运行所需依赖jar的存档。
-
-**可执行jars和Java**:Java没有提供任何标准方式,用于加载内嵌jar文件(即jar文件中还包含jar文件),这对分发自包含应用来说是个问题。为了解决该问题,很多开发者采用"共享的"jars。共享的jar只是简单地将所有jars的类打包进一个单独的存档,这种方式存在的问题是,很难区分应用程序中使用了哪些库。在多个jars中如果存在相同的文件名(但内容不一样)也会是一个问题。Spring Boot采取一个[不同的方式](../X. Appendices/D. The executable jar format.md),允许你真正的直接内嵌jars。
-
-为了创建可执行的jar,我们需要将`spring-boot-maven-plugin`添加到`pom.xml`中,在dependencies节点后面插入以下内容:
-```xml
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-```
-**注**:`spring-boot-starter-parent` POM包含绑定到repackage目标的``配置。如果不使用parent POM,你需要自己声明该配置,具体参考[插件文档](https://docs.spring.io/spring-boot/docs/2.0.0.M5/maven-plugin/usage.html)。
-
-保存`pom.xml`,并从命令行运行`mvn package`:
-```shell
-$ mvn package
-
-[INFO] Scanning for projects...
-[INFO]
-[INFO] ------------------------------------------------------------------------
-[INFO] Building myproject 0.0.1-SNAPSHOT
-[INFO] ------------------------------------------------------------------------
-[INFO] .... ..
-[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ myproject ---
-[INFO] Building jar: /Users/developer/example/spring-boot-example/target/myproject-0.0.1-SNAPSHOT.jar
-[INFO]
-[INFO] --- spring-boot-maven-plugin:2.0.0.M5:repackage (default) @ myproject ---
-[INFO] ------------------------------------------------------------------------
-[INFO] BUILD SUCCESS
-[INFO] ------------------------------------------------------------------------
-```
-如果查看target目录,你应该可以看到`myproject-0.0.1-SNAPSHOT.jar`,该文件大概有10MB。想查看内部结构,可以运行`jar tvf`:
-```shell
-$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
-```
-在该目录下,你应该还能看到一个很小的名为`myproject-0.0.1-SNAPSHOT.jar.original`的文件,这是在Spring Boot重新打包前,Maven创建的原始jar文件。
-
-可以使用`java -jar`命令运行该应用程序:
-```shell
-$ java -jar target/myproject-0.0.1-SNAPSHOT.jar
-
- . ____ _ __ _ _
- /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
-( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
- \\/ ___)| |_)| | | | | || (_| | ) ) ) )
- ' |____| .__|_| |_|_| |_\__, | / / / /
- =========|_|==============|___/=/_/_/_/
- :: Spring Boot :: (v2.0.0.M5)
-....... . . .
-....... . . . (log output here)
-....... . . .
-........ Started Example in 2.536 seconds (JVM running for 2.864)
-```
-如上所述,点击`ctrl-c`可以温雅地退出应用。
diff --git a/II. Getting started/12. What to read next.md b/II. Getting started/12. What to read next.md
deleted file mode 100644
index bdd34414..00000000
--- a/II. Getting started/12. What to read next.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 12. 接下来阅读什么
-
-希望本章节已为你提供一些Spring Boot的基础部分,并帮你找到开发自己应用的方式。如果你是任务驱动型的开发者,那可以直接跳到[spring.io](http://spring.io/),check out一些[入门指南](http://spring.io/guides/),以解决特定的"使用Spring如何做"的问题;我们也有Spring Boot相关的[How-to](../IX. ‘How-to’ guides/README.md)参考文档。
-
-[Spring Boot仓库](http://github.com/spring-projects/spring-boot)有大量可以运行的[示例](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples),这些示例代码是彼此独立的(运行或使用示例的时候不需要构建其他示例)。
-
-否则,下一步就是阅读 [III、使用Spring Boot](../III. Using Spring Boot/README.md),如果没耐心,可以跳过该章节,直接阅读 [IV、Spring Boot特性](../IV. Spring Boot features/README.md)。
diff --git a/II. Getting started/9. System Requirements.md b/II. Getting started/9. System Requirements.md
deleted file mode 100644
index f6b6bef9..00000000
--- a/II. Getting started/9. System Requirements.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 9. 系统要求
-
-Spring Boot 2.0.0.M5 需要[Java8](http://www.java.com/)环境,Spring框架5.0.0.RELEASE或以上版本。明确提供构建支持的有Maven(3.2+)和Gradle 4。
\ No newline at end of file
diff --git a/II. Getting started/9.1. Servlet containers.md b/II. Getting started/9.1. Servlet containers.md
deleted file mode 100644
index 3688e13c..00000000
--- a/II. Getting started/9.1. Servlet containers.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 9.1. Servlet容器
-
-下列内嵌容器支持开箱即用(out of the box):
-
-|名称|Servlet版本|
-|--------|:-------|
-|Tomcat 8.5|3.1|
-|Jetty 9.4|3.1|
-|Undertow 1.3|3.1|
-
-你也可以将Spring Boot应用部署到任何兼容Servlet 3.0+的容器。
diff --git a/II. Getting started/README.md b/II. Getting started/README.md
deleted file mode 100644
index 5ea4ed27..00000000
--- a/II. Getting started/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 入门指南
-
-如果你想从大体上了解Spring Boot或Spring,本章节正是你所需要的!本节中,我们会回答基本的"what?","how?"和"why?"等问题,并通过一些安装指南简单介绍下Spring Boot。然后我们会构建第一个Spring Boot应用,并讨论一些需要遵循的核心原则。
diff --git a/III. Using Spring Boot/13. Build Systems.md b/III. Using Spring Boot/13. Build Systems.md
new file mode 100644
index 00000000..5c2c2184
--- /dev/null
+++ b/III. Using Spring Boot/13. Build Systems.md
@@ -0,0 +1,3 @@
+### 13. 构建系统
+
+强烈建议你选择一个支持依赖管理,能消费发布到"Maven中央仓库"的artifacts的构建系统,比如Maven或Gradle。使用其他构建系统也是可以的,比如Ant,但它们得不到特别好的支持。
diff --git a/III. Using Spring Boot/13. Build systems.md b/III. Using Spring Boot/13. Build systems.md
deleted file mode 100644
index b6a7cfa0..00000000
--- a/III. Using Spring Boot/13. Build systems.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 13. 构建系统
-
-强烈建议你选择一个支持依赖管理,能消费发布到"Maven中央仓库"的artifacts的构建系统,比如Maven或Gradle。使用其他构建系统也是可以的,比如Ant,但它们可能得不到很好的支持。
diff --git a/III. Using Spring Boot/13.1. Dependency Management.md b/III. Using Spring Boot/13.1. Dependency Management.md
new file mode 100644
index 00000000..e720b69f
--- /dev/null
+++ b/III. Using Spring Boot/13.1. Dependency Management.md
@@ -0,0 +1,9 @@
+### 13.1. 依赖管理
+
+Spring Boot每次发布时都会提供一个它所支持的精选依赖列表。实际上,在构建配置里你不需要提供任何依赖的版本,因为Spring Boot已经替你管理好了。当更新Spring Boot时,那些依赖也会一起更新。
+
+**注** 如果有必要,你可以指定依赖的版本来覆盖Spring Boot默认版本。
+
+精选列表包括所有能够跟Spring Boot一起使用的Spring模块及第三方库,该列表支持[Maven](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-parent-pom)和[Gradle](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-gradle-dependency-management),可以作为一份标准的[材料清单(spring-boot-dependencies)](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-without-a-parent)。
+
+**注** Spring Boot每次发布都关联一个Spring框架的基础版本。强烈建议你不要自己指定Spring版本。
diff --git a/III. Using Spring Boot/13.1. Dependency management.md b/III. Using Spring Boot/13.1. Dependency management.md
deleted file mode 100644
index ce75a35d..00000000
--- a/III. Using Spring Boot/13.1. Dependency management.md
+++ /dev/null
@@ -1,9 +0,0 @@
-### 13.1. 依赖管理
-
-Spring Boot每次发布时都会提供一个它所支持的精选依赖列表。实际上,在构建配置里你不需要提供任何依赖的版本,因为Spring Boot已经替你管理好了。当更新Spring Boot时,那些依赖也会一起更新。
-
-**注** 如果有必要,你可以指定依赖的版本来覆盖Spring Boot默认版本。
-
-精选列表包括所有能够跟Spring Boot一起使用的Spring模块及第三方库,该列表支持[Maven](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-parent-pom)和[Gradle](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#build-tool-plugins-gradle-dependency-management),可以作为一份标准的[材料清单(spring-boot-dependencies)](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-maven-without-a-parent)。
-
-**注** Spring Boot每次发布都关联一个Spring框架的基础版本,所以强烈建议你不要自己指定Spring版本。
diff --git a/III. Using Spring Boot/13.2. Maven.md b/III. Using Spring Boot/13.2. Maven.md
index 5c98c2b4..f2ebaead 100644
--- a/III. Using Spring Boot/13.2. Maven.md
+++ b/III. Using Spring Boot/13.2. Maven.md
@@ -3,9 +3,9 @@
Maven用户可以继承`spring-boot-starter-parent`项目来获取合适的默认设置。该parent项目提供以下特性:
- 默认编译级别为Java 1.8
- 源码编码为UTF-8
-- 一个[Dependency management](./13.1. Dependency management.md)节点,允许你省略常见依赖的``标签,继承自`spring-boot-dependencies` POM。
+- 一个[Dependency management](./13.1. Dependency management.md)节选,管理着常见依赖的版本。允许你省略常见依赖的``标签,继承自`spring-boot-dependencies` POM。
- 恰到好处的[资源过滤](https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html)
- 恰到好处的插件配置([exec插件](http://mojo.codehaus.org/exec-maven-plugin/),[Git commit ID](https://github.com/ktoso/maven-git-commit-id-plugin),[shade](http://maven.apache.org/plugins/maven-shade-plugin/))
-- 恰到好处的对`application.properties`和`application.yml`进行筛选,包括特定profile(profile-specific)的文件,比如`application-foo.properties`和`application-foo.yml`
+- 恰到好处的对`application.properties`和`application.yml`进行筛选,包括特定profile(profile-specific)的文件,比如`application-dev.properties`和`application-dev.yml`
-最后一点:由于配置文件默认接收Spring风格的占位符(`${...}`),所以Maven filtering需改用`@..@`占位符(你可以使用Maven属性`resource.delimiter`来覆盖它)。
+最后一点:由于`application.properties`和`application.yml`接收Spring风格的占位符(`${...}`),所以Maven filtering需改用`@..@`占位符(你可以通过设置Maven属性`resource.delimiter`来覆盖它)。
diff --git a/III. Using Spring Boot/13.2.1. Inheriting the Starter Parent.md b/III. Using Spring Boot/13.2.1. Inheriting the Starter Parent.md
new file mode 100644
index 00000000..f70262ad
--- /dev/null
+++ b/III. Using Spring Boot/13.2.1. Inheriting the Starter Parent.md
@@ -0,0 +1,21 @@
+### 13.2.1. 继承starter parent
+
+如果你想配置项目,让其继承自`spring-boot-starter-parent`,只需将`parent`按如下设置:
+```xml
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.0.0.RELEASE
+
+```
+**注**:你应该只需在该依赖上指定Spring Boot版本,如果导入其他的starters,放心的省略版本号好了。
+
+按照以上设置,你可以在自己的项目中通过覆盖属性来覆盖个别的依赖。例如,你可以将以下设置添加到`pom.xml`中来升级Spring Data到另一个发布版本。
+```xml
+
+ Fowler-SR2
+
+```
+
+**注** 查看[spring-boot-dependencies pom](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-dependencies/pom.xml)获取支持的属性列表。
diff --git a/III. Using Spring Boot/13.2.1. Inheriting the starter parent.md b/III. Using Spring Boot/13.2.1. Inheriting the starter parent.md
deleted file mode 100644
index 36aec075..00000000
--- a/III. Using Spring Boot/13.2.1. Inheriting the starter parent.md
+++ /dev/null
@@ -1,21 +0,0 @@
-### 13.2.1. 继承starter parent
-
-如果你想配置项目,让其继承自`spring-boot-starter-parent`,只需将`parent`按如下设置:
-```xml
-
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.0.0.M5
-
-```
-**注**:你应该只需在该依赖上指定Spring Boot版本,如果导入其他的starters,放心的省略版本号好了。
-
-按照以上设置,你可以在自己的项目中通过覆盖属性来覆盖个别的依赖。例如,你可以将以下设置添加到`pom.xml`中来升级Spring Data到另一个发布版本。
-```xml
-
- Fowler-SR2
-
-```
-
-**注** 查看[spring-boot-dependencies pom](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-dependencies/pom.xml)获取支持的属性列表。
diff --git a/III. Using Spring Boot/13.2.2. Using Spring Boot without the Parent POM.md b/III. Using Spring Boot/13.2.2. Using Spring Boot without the Parent POM.md
new file mode 100644
index 00000000..db20b7b5
--- /dev/null
+++ b/III. Using Spring Boot/13.2.2. Using Spring Boot without the Parent POM.md
@@ -0,0 +1,43 @@
+### 13.2.2. 在不使用parent POM的情况下玩转Spring Boot
+
+不是每个人都喜欢继承`spring-boot-starter-parent` POM,比如你可能需要使用公司的标准parent,或倾向于显式声明所有的Maven配置。
+
+如果你不想使用`spring-boot-starter-parent`,通过设置`scope=import`的依赖,你仍能获取到依赖管理的好处:
+```xml
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ 2.0.0.RELEASE
+ pom
+ import
+
+
+
+```
+
+以上设置不允许你使用属性覆盖个别依赖,为了达到这个目的,你需要在项目的`dependencyManagement`节点中,在`spring-boot-dependencies`实体前插入一个节点。例如,为了将Spring Data升级到另一个发布版本,你需要将以下配置添加到`pom.xml`中:
+```xml
+
+
+
+
+ org.springframework.data
+ spring-data-releasetrain
+ Fowler-SR2
+ import
+ pom
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ 2.0.0.RELEASE
+ pom
+ import
+
+
+
+```
+**注** 示例中,我们指定了一个材料清单,但任何的依赖类型都可以通过这种方式覆盖。
diff --git a/III. Using Spring Boot/13.2.2. Using Spring Boot without the parent POM.md b/III. Using Spring Boot/13.2.2. Using Spring Boot without the parent POM.md
deleted file mode 100644
index 89fe9873..00000000
--- a/III. Using Spring Boot/13.2.2. Using Spring Boot without the parent POM.md
+++ /dev/null
@@ -1,43 +0,0 @@
-### 13.2.2. 在不使用parent POM的情况下玩转Spring Boot
-
-不是每个人都喜欢继承`spring-boot-starter-parent` POM,比如你可能需要使用公司的标准parent,或只是倾向于显式声明所有的Maven配置。
-
-如果你不想使用`spring-boot-starter-parent`,通过设置`scope=import`的依赖,你仍能获取到依赖管理的好处:
-```xml
-
-
-
-
- org.springframework.boot
- spring-boot-dependencies
- 2.0.0.M5
- pom
- import
-
-
-
-```
-
-以上设置不允许你使用属性覆盖个别依赖,为了达到这个目的,你需要在项目的`dependencyManagement`节点中,在`spring-boot-dependencies`实体前插入一个节点。例如,为了将Spring Data升级到另一个发布版本,你需要将以下配置添加到`pom.xml`中:
-```xml
-
-
-
-
- org.springframework.data
- spring-data-releasetrain
- Fowler-SR2
- import
- pom
-
-
- org.springframework.boot
- spring-boot-dependencies
- 2.0.0.M5
- pom
- import
-
-
-
-```
-**注** 示例中,我们指定了一个BOM,但任何的依赖类型都可以通过这种方式覆盖。
diff --git a/III. Using Spring Boot/13.2.3. Using the Spring Boot Maven plugin.md b/III. Using Spring Boot/13.2.3. Using the Spring Boot Maven Plugin.md
similarity index 100%
rename from III. Using Spring Boot/13.2.3. Using the Spring Boot Maven plugin.md
rename to III. Using Spring Boot/13.2.3. Using the Spring Boot Maven Plugin.md
diff --git a/III. Using Spring Boot/13.3. Gradle.md b/III. Using Spring Boot/13.3. Gradle.md
index 25de92cf..b47a24f1 100644
--- a/III. Using Spring Boot/13.3. Gradle.md
+++ b/III. Using Spring Boot/13.3. Gradle.md
@@ -2,5 +2,5 @@
想要学习用Gradle配置Spring Boot,请参考Spring Boot的Gradle插件的文档。
- - Reference ( [HTML](http://docs.spring.io/spring-boot/docs/2.0.0.M3/gradle-plugin//reference/html) and [PDF](http://docs.spring.io/spring-boot/docs/2.0.0.M3/gradle-plugin//reference/pdf/spring-boot-gradle-plugin-reference.pdf) )
- - [API](http://docs.spring.io/spring-boot/docs/2.0.0.M3/gradle-plugin//api)
\ No newline at end of file
+ - 参考([HTML](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/gradle-plugin/reference/html) 与 [PDF](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/gradle-plugin/reference/pdf/spring-boot-gradle-plugin-reference.pdf))
+ - [API](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/gradle-plugin/api)
diff --git a/III. Using Spring Boot/13.4. Ant.md b/III. Using Spring Boot/13.4. Ant.md
index 747e725c..fa538582 100644
--- a/III. Using Spring Boot/13.4. Ant.md
+++ b/III. Using Spring Boot/13.4. Ant.md
@@ -21,7 +21,7 @@
xmlns:spring-boot="antlib:org.springframework.boot.ant"
name="myapp" default="build">
-
+
@@ -51,4 +51,4 @@
```
-**注** 如果你不想使用`spring-boot-antlib`模块,那查看[章节 85.9,使用Ant构建可执行存档(不使用spring-boot-antlib)](../IX. ‘How-to’ guides/85.9 Build an executable archive from Ant without using spring-boot-antlib.md)获取更多指导。
+**注** 如果你不想使用`spring-boot-antlib`模块,那查看[章节 86.9,使用Ant构建可执行存档(不使用spring-boot-antlib)](../IX. ‘How-to’ guides/86.9 Build an Executable Archive from Ant without Using spring-boot-antlib.md)获取更多指导。
\ No newline at end of file
diff --git a/III. Using Spring Boot/13.5. Starters.md b/III. Using Spring Boot/13.5. Starters.md
index f19714ed..eb350159 100644
--- a/III. Using Spring Boot/13.5. Starters.md
+++ b/III. Using Spring Boot/13.5. Starters.md
@@ -1,10 +1,11 @@
### 13.5. Starters
-Starters是一个依赖描述符的集合,你可以将它包含进项目中,这样添加依赖就非常方便。你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符。例如,如果你想使用Spring和JPA进行数据库访问,只需要在项目中包含`spring-boot-starter-data-jpa`依赖,然后你就可以开始了。
+Starters是一个依赖描述符的集合,你可以将它包含进项目中,这样添加依赖就非常方便。你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符。例如,如果你想使用Spring和JPA进行数据库访问,需要在项目中包含`spring-boot-starter-data-jpa`依赖。
该starters包含很多搭建,快速运行项目所需的依赖,并提供一致的,可管理传递性的依赖集。
-**名字有什么含义**:所有官方starters遵循相似的命名模式:`spring-boot-starter-*`,在这里`*`是一种特殊的应用程序类型。该命名结构旨在帮你找到需要的starter。很多集成于IDEs中的Maven插件允许你通过名称name搜索依赖。例如,使用相应的Eclipse或STS插件,你可以简单地在POM编辑器中点击`ctrl-space`,然后输入"spring-boot-starter"就可以获取一个完整列表。正如[Creating your own starter](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-custom-starter)章节中讨论的,第三方starters不应该以`spring-boot`开头,因为它跟Spring Boot官方artifacts冲突。一个acme的第三方starter通常命名为`acme-spring-boot-starter`。
+**名字有什么含义**:所有官方starters遵循相似的命名模式:`spring-boot-starter-*`,在这里`*`是一种特殊的应用程序类型。该命名结构旨在帮你找到需要的starter。很多集成于IDEs中的Maven插件让你通过名称搜索依赖。例如,使用相应的Eclipse或STS插件,你可以在POM编辑器中点击`ctrl-space`,然后输入"spring-boot-starter"就可以获取一个完整列表。
+正如[创建自己的starter](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-custom-starter)章节中讨论的,第三方starters不应该以`spring-boot`开头,因为它跟Spring Boot官方artifacts冲突。第三方starter通常会用项目的名称开头。例如,一个叫做`thirdpartyproject`的第三方starter项目,通常会被命名为`thirdpartyproject-spring-boot-starter`。
以下应用程序starters是Spring Boot在`org.springframework.boot` group下提供的:
@@ -12,53 +13,51 @@ Starters是一个依赖描述符的集合,你可以将它包含进项目中,
|名称|描述|Pom|
|------|:-----|:-----|
-|spring-boot-starter|核心starter,包括自动配置支持,日志和YAML|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter/pom.xml)|
-|spring-boot-starter-activemq|用于使用Apache ActiveMQ实现JMS消息|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/pom.xml)|
-|spring-boot-starter-amqp|用于使用Spring AMQP和Rabbit MQ|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-amqp/pom.xml)|
-|spring-boot-starter-aop|用于使用Spring AOP和AspectJ实现面向切面编程|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-aop/pom.xml)|
-|spring-boot-starter-artemis|使用Apache Artemis实现JMS消息|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/pom.xml)|
-|spring-boot-starter-batch|对Spring Batch的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-batch/pom.xml)|
-|spring-boot-starter-cache|用于使用Spring框架的缓存支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-cache/pom.xml)|
-|spring-boot-starter-cloud-connectors|对Spring Cloud Connectors的支持,用于简化云平台下(例如Cloud Foundry 和Heroku)服务的连接|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-cloud-connectors/pom.xml)|
-|spring-boot-starter-data-cassandra|用于使用分布式数据库Cassandra和Spring Data Cassandra|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-cassandra/pom.xml)|
-|spring-boot-starter-data-cassandra-reactive|用于使用分布式数据库Cassandra和Spring Data Cassandra Reactive|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-cassandra-reactive/pom.xml)|
-|spring-boot-starter-data-couchbase|用于使用基于文档的数据库Couchbase和Spring Data Couchbase|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-couchbase/pom.xml)|
-|spring-boot-starter-data-elasticsearch|用于使用Elasticsearch搜索,分析引擎和Spring Data Elasticsearch|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml)|
-|spring-boot-starter-data-jpa|用于使用Hibernate实现Spring Data JPA|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/pom.xml)|
-|spring-boot-starter-data-ldap|用于Spring Data LDAP|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-ldap/pom.xml)|
-|spring-boot-starter-data-mongodb|用于使用基于文档的数据库MongoDB和Spring Data MongoDB|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-mongodb/pom.xml)|
-|spring-boot-starter-data-mongodb-reactive|用于使用基于文档的数据库MongoDB和Spring Data MongoDB Reactive|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml)|
-|spring-boot-starter-data-neo4j|用于使用图数据库Neo4j和Spring Data Neo4j|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-neo4j/pom.xml)|
-|spring-boot-starter-data-redis|用于使用Spring Data Redis和Lettuce客户端操作键-值存储的Redis|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-redis/pom.xml)|
-|spring-boot-starter-data-rest|用于使用Spring Data REST暴露基于REST的Spring Data仓库|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-rest/pom.xml)|
-|spring-boot-starter-data-solr|通过Spring Data Solr使用Apache Solr搜索平台|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-data-solr/pom.xml)|
-|spring-boot-starter-freemarker|用于使用FreeMarker模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-freemarker/pom.xml)|
-|spring-boot-starter-groovy-templates|用于使用Groovy模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-groovy-templates/pom.xml)|
-|spring-boot-starter-hateoas|用于使用Spring MVC和Spring HATEOAS实现基于超媒体的RESTful web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-hateoas/pom.xml)|
-|spring-boot-starter-integration|用于使用Spring Integration|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-integration/pom.xml)|
-|spring-boot-starter-jdbc|对JDBC的支持(使用Tomcat JDBC连接池)|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jdbc/pom.xml)|
-|spring-boot-starter-jersey|用于使用JAX-RS和Jersey构建RESTful web应用,可使用[spring-boot-starter-web](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-web)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jersey/pom.xml)|
-|spring-boot-starter-jooq|用于使用JOOQ访问SQL数据库,可使用[spring-boot-starter-data-jpa](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-data-jpa)或[spring-boot-starter-jdbc](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-jdbc)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jooq/pom.xml)|
-|spring-boot-starter-json|用于读写json|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-json/pom.xmll)|
-|spring-boot-starter-jta-atomikos|用于使用Atomikos实现JTA事务|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-atomikos/pom.xml)|
-|spring-boot-starter-jta-bitronix|用于使用Bitronix实现JTA事务|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml)|
-|spring-boot-starter-jta-narayana|Spring Boot Narayana JTA Starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-narayana/pom.xml)|
-|spring-boot-starter-mail|用于使用Java Mail和Spring框架email发送支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-mail/pom.xml)|
-|spring-boot-starter-mobile|用于使用Spring Mobile开发web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-mobile/pom.xml)|
-|spring-boot-starter-mustache|用于使用Mustache模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-mustache/pom.xml)|
-|spring-boot-starter-quartz|Spring Boot Quartz Starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-quartz/pom.xml)|
-|spring-boot-starter-security|对Spring Security的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-security/pom.xml)|
-|spring-boot-starter-security-reactive|对响应式Spring Security的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-security-reactive/pom.xml)|
-|spring-boot-starter-social-facebook|用于使用Spring Social Facebook|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-social-facebook/pom.xml)|
-|spring-boot-starter-social-linkedin|用于使用Spring Social LinkedIn|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-social-linkedin/pom.xml)|
-|spring-boot-starter-social-twitter|对使用Spring Social Twitter的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-social-twitter/pom.xml)|
-|spring-boot-starter-test|用于测试Spring Boot应用,支持常用测试类库,包括JUnit, Hamcrest和Mockito|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-test/pom.xml)|
-|spring-boot-starter-thymeleaf|用于使用Thymeleaf模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml)|
-|spring-boot-starter-validation|用于使用Hibernate Validator实现Java Bean校验|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-validation/pom.xml)|
-|spring-boot-starter-web|用于使用Spring MVC构建web应用,包括RESTful。Tomcat是默认的内嵌容器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-web/pom.xml)|
-|spring-boot-starter-web-services|对Spring Web服务的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-web-services/pom.xml)|
-|spring-boot-starter-webflux|提供用Spring框架创建webflux应用的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-webflux/pom.xml)|
-|spring-boot-starter-websocket|用于使用Spring框架的WebSocket支持构建WebSocket应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/pom.xml)|
+|spring-boot-starter|核心starter,包括自动配置支持,日志和YAML|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter/pom.xml)|
+|spring-boot-starter-activemq|用于使用Apache ActiveMQ实现JMS消息|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/pom.xml)|
+|spring-boot-starter-amqp|用于使用Spring AMQP和Rabbit MQ|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-amqp/pom.xml)|
+|spring-boot-starter-aop|用于使用Spring AOP和AspectJ实现面向切面编程|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-aop/pom.xml)|
+|spring-boot-starter-artemis|使用Apache Artemis实现JMS消息|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/pom.xml)|
+|spring-boot-starter-batch|对Spring Batch的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-batch/pom.xml)|
+|spring-boot-starter-cache|用于使用Spring框架的缓存支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-cache/pom.xml)|
+|spring-boot-starter-cloud-connectors|对Spring Cloud Connectors的支持,用于简化云平台下(例如Cloud Foundry 和Heroku)服务的连接|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-cloud-connectors/pom.xml)|
+|spring-boot-starter-data-cassandra|用于使用分布式数据库Cassandra和Spring Data Cassandra|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-cassandra/pom.xml)|
+|spring-boot-starter-data-cassandra-reactive|用于使用分布式数据库Cassandra和Spring Data Cassandra Reactive|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-cassandra-reactive/pom.xml)|
+|spring-boot-starter-data-couchbase|用于使用基于文档的数据库Couchbase和Spring Data Couchbase|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-couchbase/pom.xml)|
+|spring-boot-starter-data-couchbase-reactive|用于使用基于文档的数据库Couchbase和Spring Data Couchbase Reactive|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-couchbase-reactive/pom.xml)|
+|spring-boot-starter-data-elasticsearch|用于使用Elasticsearch搜索,分析引擎和Spring Data Elasticsearch|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-elasticsearch/pom.xml)|
+|spring-boot-starter-data-jpa|用于使用Hibernate实现Spring Data JPA|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-jpa/pom.xml)|
+|spring-boot-starter-data-ldap|用于Spring Data LDAP|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-ldap/pom.xml)|
+|spring-boot-starter-data-mongodb|用于使用基于文档的数据库MongoDB和Spring Data MongoDB|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-mongodb/pom.xml)|
+|spring-boot-starter-data-mongodb-reactive|用于使用基于文档的数据库MongoDB和Spring Data MongoDB Reactive|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-mongodb-reactive/pom.xml)|
+|spring-boot-starter-data-neo4j|用于使用图数据库Neo4j和Spring Data Neo4j|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-neo4j/pom.xml)|
+|spring-boot-starter-data-redis|用于使用Spring Data Redis和Lettuce客户端操作键-值存储的Redis|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-redis/pom.xml)|
+|spring-boot-starter-data-redis-reactive|用于使用Spring Data Redis reactive和Lettuce客户端操作键-值存储的Redis|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-redis-reactive/pom.xml)|
+|spring-boot-starter-data-rest|用于使用Spring Data REST暴露基于REST的Spring Data仓库|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-rest/pom.xml)|
+|spring-boot-starter-data-solr|通过Spring Data Solr使用Apache Solr搜索平台|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-data-solr/pom.xml)|
+|spring-boot-starter-freemarker|用于使用FreeMarker模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-freemarker/pom.xml)|
+|spring-boot-starter-groovy-templates|用于使用Groovy模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-groovy-templates/pom.xml)|
+|spring-boot-starter-hateoas|用于使用Spring MVC和Spring HATEOAS实现基于超媒体的RESTful web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-hateoas/pom.xml)|
+|spring-boot-starter-integration|用于使用Spring Integration|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-integration/pom.xml)|
+|spring-boot-starter-jdbc|对JDBC的支持(使用Tomcat JDBC连接池)|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jdbc/pom.xml)|
+|spring-boot-starter-jersey|用于使用JAX-RS和Jersey构建RESTful web应用,可使用[spring-boot-starter-web](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-web)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jersey/pom.xml)|
+|spring-boot-starter-jooq|用于使用JOOQ访问SQL数据库,可使用[spring-boot-starter-data-jpa](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-data-jpa)或[spring-boot-starter-jdbc](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-jdbc)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jooq/pom.xml)|
+|spring-boot-starter-json|用于读写json|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-json/pom.xmll)|
+|spring-boot-starter-jta-atomikos|用于使用Atomikos实现JTA事务|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-atomikos/pom.xml)|
+|spring-boot-starter-jta-bitronix|用于使用Bitronix实现JTA事务|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-bitronix/pom.xml)|
+|spring-boot-starter-jta-narayana|Spring Boot Narayana JTA Starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jta-narayana/pom.xml)|
+|spring-boot-starter-mail|用于使用Java Mail和Spring框架email发送支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-mail/pom.xml)|
+|spring-boot-starter-mustache|用于使用Mustache模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-mustache/pom.xml)|
+|spring-boot-starter-quartz|Spring Boot Quartz Starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-quartz/pom.xml)|
+|spring-boot-starter-security|对Spring Security的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-security/pom.xml)|
+|spring-boot-starter-security-reactive|对响应式Spring Security的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-security-reactive/pom.xml)|
+|spring-boot-starter-test|用于测试Spring Boot应用,支持常用测试类库,包括JUnit, Hamcrest和Mockito|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-test/pom.xml)|
+|spring-boot-starter-thymeleaf|用于使用Thymeleaf模板引擎构建MVC web应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml)|
+|spring-boot-starter-validation|用于使用Hibernate Validator实现Java Bean校验|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-validation/pom.xml)|
+|spring-boot-starter-web|用于使用Spring MVC构建web应用,包括RESTful。Tomcat是默认的内嵌容器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-web/pom.xml)|
+|spring-boot-starter-web-services|对Spring Web服务的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-web-services/pom.xml)|
+|spring-boot-starter-webflux|提供用Spring框架创建webflux应用的支持|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-webflux/pom.xml)|
+|spring-boot-starter-websocket|用于使用Spring框架的WebSocket支持构建WebSocket应用|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-websocket/pom.xml)|
除了应用程序starters,以下starters可用于添加[production ready](../V. Spring Boot Actuator/README.md)的功能:
@@ -67,20 +66,20 @@ Starters是一个依赖描述符的集合,你可以将它包含进项目中,
|名称|描述|Pom|
|----|:----|:----|
-|spring-boot-starter-actuator|用于使用Spring Boot的Actuator,它提供了production ready功能来帮助你监控和管理应用程序|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-actuator/pom.xml)|
+|spring-boot-starter-actuator|用于使用Spring Boot的Actuator,它提供了production ready功能来帮助你监控和管理应用程序|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-actuator/pom.xml)|
-最后,Spring Boot还包含一些用于排除或交换某些特定技术方面的starters:
+最后,Spring Boot还包含以下用于排除或交换某些特定技术方面的starters:
**表 13.3. Spring Boot技术性starters**
|名称|描述|Pom|
|------|:------|:------|
-|spring-boot-starter-jetty|用于使用Jetty作为内嵌servlet容器,可使用[spring-boot-starter-tomcat](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-tomcat)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml)|
-|spring-boot-starter-log4j2|用于使用Log4j2记录日志,可使用[spring-boot-starter-logging](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-logging)代替|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-log4j2/pom.xml)|
-|spring-boot-starter-logging|用于使用Logback记录日志,默认的日志starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-logging/pom.xml)|
-|spring-boot-starter-reactor-netty|使用Reactor Netty做为内嵌的HTTP服务器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-reactor-netty/pom.xml)|
-|spring-boot-starter-tomcat|用于使用Tomcat作为内嵌servlet容器,[spring-boot-starter-web](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-web)使用的默认servlet容器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-tomcat/pom.xml)|
-|spring-boot-starter-undertow|用于使用Undertow作为内嵌servlet容器,可使用[spring-boot-starter-tomcat](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#spring-boot-starter-tomcat)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml)|
+|spring-boot-starter-jetty|用于使用Jetty作为内嵌servlet容器,可使用[spring-boot-starter-tomcat](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-tomcat)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml)|
+|spring-boot-starter-log4j2|用于使用Log4j2记录日志,可使用[spring-boot-starter-logging](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-logging)代替|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-log4j2/pom.xml)|
+|spring-boot-starter-logging|用于使用Logback记录日志,默认的日志starter|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-logging/pom.xml)|
+|spring-boot-starter-reactor-netty|使用Reactor Netty做为内嵌的HTTP服务器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-reactor-netty/pom.xml)|
+|spring-boot-starter-tomcat|用于使用Tomcat作为内嵌servlet容器,[spring-boot-starter-web](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-web)使用的默认servlet容器|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-tomcat/pom.xml)|
+|spring-boot-starter-undertow|用于使用Undertow作为内嵌servlet容器,可使用[spring-boot-starter-tomcat](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#spring-boot-starter-tomcat)替代|[Pom](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml)|
**注**:查看GitHub上位于`spring-boot-starters`模块内的[README文件](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-starters/README.adoc),可以获取到一个社区贡献的其他starters列表。
diff --git a/III. Using Spring Boot/14. Structuring Your Code.md b/III. Using Spring Boot/14. Structuring Your Code.md
new file mode 100644
index 00000000..dcced825
--- /dev/null
+++ b/III. Using Spring Boot/14. Structuring Your Code.md
@@ -0,0 +1,3 @@
+### 14. 组织你的代码
+
+Spring Boot不要求使用任何特殊的代码结构。不过,遵循以下的一些最佳实践还是挺有帮助的。
diff --git a/III. Using Spring Boot/14. Structuring your code.md b/III. Using Spring Boot/14. Structuring your code.md
deleted file mode 100644
index 7ad1771a..00000000
--- a/III. Using Spring Boot/14. Structuring your code.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 14. 组织你的代码
-
-Spring Boot不要求使用任何特殊的代码结构,不过,遵循以下的一些最佳实践还是挺有帮助的。
diff --git "a/III. Using Spring Boot/14.1. Using the \342\200\234default\342\200\235 package.md" "b/III. Using Spring Boot/14.1. Using the \342\200\234default\342\200\235 Package.md"
similarity index 100%
rename from "III. Using Spring Boot/14.1. Using the \342\200\234default\342\200\235 package.md"
rename to "III. Using Spring Boot/14.1. Using the \342\200\234default\342\200\235 Package.md"
diff --git a/III. Using Spring Boot/14.2. Locating the main application class.md b/III. Using Spring Boot/14.2. Locating the Main Application Class.md
similarity index 100%
rename from III. Using Spring Boot/14.2. Locating the main application class.md
rename to III. Using Spring Boot/14.2. Locating the Main Application Class.md
diff --git a/III. Using Spring Boot/15. Configuration Classes.md b/III. Using Spring Boot/15. Configuration Classes.md
new file mode 100644
index 00000000..8f39dbec
--- /dev/null
+++ b/III. Using Spring Boot/15. Configuration Classes.md
@@ -0,0 +1,5 @@
+### 15. 配置类
+
+Spring Boot提倡基于Java的配置。尽管你可以通过XML源来使用`SpringApplication`,不过还是建议你使用`@Configuration`类作为主要配置源。通常定义了`main`方法的类是使用`@Configuration`注解的一个很好的替补。
+
+**注**:虽然网络上有很多使用XML配置的Spring示例,但你应该尽可能的使用基于Java的配置,搜索查看`Enable*`注解就是一个好的开端。
diff --git a/III. Using Spring Boot/15. Configuration classes.md b/III. Using Spring Boot/15. Configuration classes.md
deleted file mode 100644
index b655b3e1..00000000
--- a/III. Using Spring Boot/15. Configuration classes.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 15. 配置类
-
-Spring Boot提倡基于Java的配置。尽管你可以通过XML源来使用`SpringApplication`,不过还是建议你使用`@Configuration`类作为主要配置源。通常定义了`main`方法的类也是使用`@Configuration`注解的一个很好的替补。
-
-**注**:虽然网络上有很多使用XML配置的Spring示例,但你应该尽可能的使用基于Java的配置,搜索查看`Enable*`注解就是一个好的开端。
diff --git a/III. Using Spring Boot/15.1. Importing additional configuration classes.md b/III. Using Spring Boot/15.1. Importing Additional Configuration Classes.md
similarity index 100%
rename from III. Using Spring Boot/15.1. Importing additional configuration classes.md
rename to III. Using Spring Boot/15.1. Importing Additional Configuration Classes.md
diff --git a/III. Using Spring Boot/15.2. Importing XML configuration.md b/III. Using Spring Boot/15.2. Importing XML Configuration.md
similarity index 100%
rename from III. Using Spring Boot/15.2. Importing XML configuration.md
rename to III. Using Spring Boot/15.2. Importing XML Configuration.md
diff --git a/III. Using Spring Boot/16.1. Gradually Replacing Auto-configuration.md b/III. Using Spring Boot/16.1. Gradually Replacing Auto-configuration.md
new file mode 100644
index 00000000..eaa69040
--- /dev/null
+++ b/III. Using Spring Boot/16.1. Gradually Replacing Auto-configuration.md
@@ -0,0 +1,5 @@
+### 16.1. 逐步替换自动配置
+
+自动配置(Auto-configuration)是非侵入性的,任何时候你都可以定义自己的配置类来替换自动配置的特定部分。例如,如果你添加自己的`DataSource` bean,默认的内嵌数据库支持将不被考虑。
+
+如果需要查看当前应用启动了哪些自动配置项,你可以在运行应用时打开`--debug`开关,这将为核心日志开启debug日志级别,并将配置情况输出到控制台。
diff --git a/III. Using Spring Boot/16.1. Gradually replacing auto-configuration.md b/III. Using Spring Boot/16.1. Gradually replacing auto-configuration.md
deleted file mode 100644
index d0794200..00000000
--- a/III. Using Spring Boot/16.1. Gradually replacing auto-configuration.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 16.1. 逐步替换自动配置
-
-自动配置(Auto-configuration)是非侵入性的,任何时候你都可以定义自己的配置类来替换自动配置的特定部分。例如,如果你添加自己的`DataSource` bean,默认的内嵌数据库支持将不被考虑。
-
-如果需要查看当前应用启动了哪些自动配置项,你可以在运行应用时打开`--debug`开关,这将为核心日志开启debug日志级别,并将自动配置相关的日志输出到控制台。
diff --git a/III. Using Spring Boot/16.2. Disabling Specific Auto-configuration Classes.md b/III. Using Spring Boot/16.2. Disabling Specific Auto-configuration Classes.md
new file mode 100644
index 00000000..b56a20fb
--- /dev/null
+++ b/III. Using Spring Boot/16.2. Disabling Specific Auto-configuration Classes.md
@@ -0,0 +1,16 @@
+### 16.2. 禁用特定的自动配置类
+
+如果发现启用了不想要的自动配置类,你可以使用`@EnableAutoConfiguration`注解的exclude属性禁用它们:
+```java
+import org.springframework.boot.autoconfigure.*;
+import org.springframework.boot.autoconfigure.jdbc.*;
+import org.springframework.context.annotation.*;
+
+@Configuration
+@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
+public class MyConfiguration {
+}
+```
+如果该类不在classpath中,你可以使用该注解的excludeName属性,并指定全限定名来达到相同效果。最后,你可以通过`spring.autoconfigure.exclude`属性exclude多个自动配置项(一个自动配置项集合)。
+
+**注** 通过注解级别或exclude属性都可以定义排除项。
diff --git a/III. Using Spring Boot/16.2. Disabling specific auto-configuration.md b/III. Using Spring Boot/16.2. Disabling specific auto-configuration.md
deleted file mode 100644
index 2807663f..00000000
--- a/III. Using Spring Boot/16.2. Disabling specific auto-configuration.md
+++ /dev/null
@@ -1,16 +0,0 @@
-### 16.2. 禁用特定的自动配置项
-
-如果发现启用了不想要的自动配置项,你可以使用`@EnableAutoConfiguration`注解的exclude属性禁用它们:
-```java
-import org.springframework.boot.autoconfigure.*;
-import org.springframework.boot.autoconfigure.jdbc.*;
-import org.springframework.context.annotation.*;
-
-@Configuration
-@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
-public class MyConfiguration {
-}
-```
-如果该类不在classpath中,你可以使用该注解的excludeName属性,并指定全限定名来达到相同效果。最后,你可以通过`spring.autoconfigure.exclude`属性exclude多个自动配置项(一个自动配置项集合)。
-
-**注** 通过注解级别或exclude属性都可以定义排除项。
diff --git a/III. Using Spring Boot/17. Spring Beans and Dependency Injection.md b/III. Using Spring Boot/17. Spring Beans and Dependency Injection.md
new file mode 100644
index 00000000..c54c5519
--- /dev/null
+++ b/III. Using Spring Boot/17. Spring Beans and Dependency Injection.md
@@ -0,0 +1,44 @@
+### 17. Spring Beans和依赖注入
+
+你可以自由地使用任何标准的Spring框架技术去定义bean和它们注入的依赖。简单起见,我们经常发现使用`@ComponentScan`(用来注解搜索bean)和`@Autowired`(用来构造器注入)能够很好地工作。
+
+如果遵循以上的建议组织代码结构(将应用的main类放到包的最上层,即root package),那么你就可以添加`@ComponentScan`注解而不需要任何参数,所有应用组件(`@Component`, `@Service`, `@Repository`, `@Controller`等)都会自动注册成Spring Beans。
+
+下面是一个`@Service` Bean的示例,它使用构建器注入获取一个需要的`RiskAssessor` bean:
+```java
+package com.example.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DatabaseAccountService implements AccountService {
+
+ private final RiskAssessor riskAssessor;
+
+ @Autowired
+ public DatabaseAccountService(RiskAssessor riskAssessor) {
+ this.riskAssessor = riskAssessor;
+ }
+
+ // ...
+}
+```
+
+如果bean里面有一个构造器,你可以省略`@Autowired`。
+```java
+@Service
+public class DatabaseAccountService implements AccountService {
+
+ private final RiskAssessor riskAssessor;
+
+ public DatabaseAccountService(RiskAssessor riskAssessor) {
+
+ this .riskAssessor = riskAssessor;
+ }
+
+// ...
+
+}
+```
+**注** 注意使用构建器注入允许`riskAssessor`字段被标记为`final`,这意味着`riskAssessor`后续是不能改变的。
diff --git a/III. Using Spring Boot/17. Spring Beans and dependency injection.md b/III. Using Spring Boot/17. Spring Beans and dependency injection.md
deleted file mode 100644
index d08ad1a4..00000000
--- a/III. Using Spring Boot/17. Spring Beans and dependency injection.md
+++ /dev/null
@@ -1,44 +0,0 @@
-### 17. Spring Beans和依赖注入
-
-你可以自由地使用任何标准的Spring框架技术去定义beans和它们注入的依赖。简单起见,我们经常使用`@ComponentScan`注解搜索beans,并结合`@Autowired`构造器注入。
-
-如果遵循以上的建议组织代码结构(将应用的main类放到包的最上层,即root package),那么你就可以添加`@ComponentScan`注解而不需要任何参数,所有应用组件(`@Component`, `@Service`, `@Repository`, `@Controller`等)都会自动注册成Spring Beans。
-
-下面是一个`@Service` Bean的示例,它使用构建器注入获取一个需要的`RiskAssessor` bean。
-```java
-package com.example.service;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-@Service
-public class DatabaseAccountService implements AccountService {
-
- private final RiskAssessor riskAssessor;
-
- @Autowired
- public DatabaseAccountService(RiskAssessor riskAssessor) {
- this.riskAssessor = riskAssessor;
- }
-
- // ...
-}
-```
-
-如果bean里面有一个构造器,你可以省略`@Autowired`。
-```java
-@Service
-public class DatabaseAccountService implements AccountService {
-
- private final RiskAssessor riskAssessor;
-
- public DatabaseAccountService(RiskAssessor riskAssessor) {
-
- this .riskAssessor = riskAssessor;
- }
-
-// ...
-
-}
-```
-**注** 注意使用构建器注入允许`riskAssessor`字段被标记为`final`,这意味着`riskAssessor`后续是不能改变的。
diff --git a/III. Using Spring Boot/18. Using the @SpringBootApplication annotation.md b/III. Using Spring Boot/18. Using the @SpringBootApplication Annotation.md
similarity index 100%
rename from III. Using Spring Boot/18. Using the @SpringBootApplication annotation.md
rename to III. Using Spring Boot/18. Using the @SpringBootApplication Annotation.md
diff --git a/III. Using Spring Boot/19. Running Your Application.md b/III. Using Spring Boot/19. Running Your Application.md
new file mode 100644
index 00000000..a6e5505b
--- /dev/null
+++ b/III. Using Spring Boot/19. Running Your Application.md
@@ -0,0 +1,5 @@
+### 19. 运行应用程序
+
+将应用打包成jar,并使用内嵌HTTP服务器的一个最大好处是,你可以像其他方式那样运行你的应用程序。调试Spring Boot应用也很简单。你都不需要任何特殊IDE插件或扩展。
+
+**注**:本章节只覆盖基于jar的打包。如果选择将应用打包成war文件,你最好参考相关的服务器和IDE文档。
diff --git a/III. Using Spring Boot/19. Running your application.md b/III. Using Spring Boot/19. Running your application.md
deleted file mode 100644
index b7b6c8d3..00000000
--- a/III. Using Spring Boot/19. Running your application.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 19. 运行应用程序
-
-将应用打包成jar,并使用内嵌HTTP服务器的一个最大好处是,你可以像其他方式那样运行你的应用程序。调试Spring Boot应用也很简单,你都不需要任何特殊IDE插件或扩展!
-
-**注**:本章节只覆盖基于jar的打包,如果选择将应用打包成war文件,你最好参考相关的服务器和IDE文档。
diff --git a/III. Using Spring Boot/19.1. Running from an IDE.md b/III. Using Spring Boot/19.1. Running from an IDE.md
index a2d272de..3f7c2d8f 100644
--- a/III. Using Spring Boot/19.1. Running from an IDE.md
+++ b/III. Using Spring Boot/19.1. Running from an IDE.md
@@ -1,7 +1,7 @@
### 19.1. 从IDE中运行
-你可以从IDE中运行Spring Boot应用,就像一个简单的Java应用,但首先需要导入项目。导入步骤取决于你的IDE和构建系统,大多数IDEs能够直接导入Maven项目,例如Eclipse用户可以选择`File`菜单的`Import…` --> `Existing Maven Projects`。
+你可以从IDE中运行Spring Boot应用,就像一个简单的Java应用。但首先需要导入项目。导入步骤取决于你的IDE和构建系统,大多数IDEs能够直接导入Maven项目。例如Eclipse用户可以选择`File`菜单的`Import…` --> `Existing Maven Projects`。
-如果不能直接将项目导入IDE,你可以使用构建系统生成IDE的元数据。Maven有针对[Eclipse](http://maven.apache.org/plugins/maven-eclipse-plugin/)和[IDEA](http://maven.apache.org/plugins/maven-idea-plugin/)的插件;Gradle为[各种IDEs](http://www.gradle.org/docs/current/userguide/ide_support.html)提供插件。
+如果不能直接将项目导入IDE,你可以使用构建系统生成IDE的元数据。Maven有针对[Eclipse](http://maven.apache.org/plugins/maven-eclipse-plugin/)和[IDEA](http://maven.apache.org/plugins/maven-idea-plugin/)的插件。Gradle为[各种IDEs](http://www.gradle.org/docs/current/userguide/ide_support.html)提供插件。
**注** 如果意外地多次运行一个web应用,你将看到一个"端口已被占用"的错误。STS用户可以使用`Relaunch`而不是`Run`按钮,以确保任何存在的实例是关闭的。
diff --git a/III. Using Spring Boot/19.2. Running as a packaged application.md b/III. Using Spring Boot/19.2. Running as a Packaged Application.md
similarity index 100%
rename from III. Using Spring Boot/19.2. Running as a packaged application.md
rename to III. Using Spring Boot/19.2. Running as a Packaged Application.md
diff --git a/III. Using Spring Boot/19.3. Using the Maven Plugin.md b/III. Using Spring Boot/19.3. Using the Maven Plugin.md
new file mode 100644
index 00000000..a91f3eab
--- /dev/null
+++ b/III. Using Spring Boot/19.3. Using the Maven Plugin.md
@@ -0,0 +1,10 @@
+### 19.3. 使用Maven插件运行
+
+Spring Boot Maven插件包含一个`run`目标,可用来快速编译和运行应用程序,并且跟在IDE运行一样支持热加载。下面的例子展示了运行Spring Boot应用的一个典型的Maven命令:
+```shell
+$ mvn spring-boot:run
+```
+你可能还会想使用操作系统环境变量`MAVEN_OPTS`:
+```shell
+$ export MAVEN_OPTS=-Xmx1024m
+```
diff --git a/III. Using Spring Boot/19.3. Using the Maven plugin.md b/III. Using Spring Boot/19.3. Using the Maven plugin.md
deleted file mode 100644
index d4351558..00000000
--- a/III. Using Spring Boot/19.3. Using the Maven plugin.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 19.3. 使用Maven插件运行
-
-Spring Boot Maven插件包含一个`run`目标,可用来快速编译和运行应用程序,并且跟在IDE运行一样支持热加载。
-```shell
-$ mvn spring-boot:run
-```
-你可以使用一些有用的操作系统环境变量:
-```shell
-$ export MAVEN_OPTS=-Xmx1024m
-```
diff --git a/III. Using Spring Boot/19.4. Using the Gradle Plugin.md b/III. Using Spring Boot/19.4. Using the Gradle Plugin.md
new file mode 100644
index 00000000..b1fc822e
--- /dev/null
+++ b/III. Using Spring Boot/19.4. Using the Gradle Plugin.md
@@ -0,0 +1,10 @@
+### 19.4. 使用Gradle插件运行
+
+Spring Boot Gradle插件也包含一个`bootRun`任务,可用来运行你的应用程序。无论你何时应用 `org.springframework.boot`和`java plugins`,`bootRun`任务总会被添加进去。
+```shell
+$ gradle bootRun
+```
+你可能还会想使用操作系统环境变量`JAVA_OPTS`:
+```shell
+$ export JAVA_OPTS=-Xmx1024m
+```
diff --git a/III. Using Spring Boot/19.4. Using the Gradle plugin.md b/III. Using Spring Boot/19.4. Using the Gradle plugin.md
deleted file mode 100644
index 6372fb55..00000000
--- a/III. Using Spring Boot/19.4. Using the Gradle plugin.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 19.4. 使用Gradle插件运行
-
-Spring Boot Gradle插件也包含一个`bootRun`任务,可用来运行你的应用程序。无论你何时应用 `org.springframework.boot`和`java plugins`,`bootRun`任务总会被添加进去。
-```shell
-$ gradle bootRun
-```
-你可能想使用一些有用的操作系统环境变量:
-```shell
-$ export JAVA_OPTS=-Xmx1024m
-```
diff --git a/III. Using Spring Boot/19.5. Hot Swapping.md b/III. Using Spring Boot/19.5. Hot Swapping.md
new file mode 100755
index 00000000..45ce21f6
--- /dev/null
+++ b/III. Using Spring Boot/19.5. Hot Swapping.md
@@ -0,0 +1,5 @@
+### 19.5. 热交换
+
+由于Spring Boot应用只是普通的Java应用,所以JVM热交换(hot-swapping)也能开箱即用。不过JVM热交换能替换的字节码有限制。想要更彻底的解决方案可以使用[JRebel](http://zeroturnaround.com/software/jrebel/)。
+
+`spring-boot-devtools`模块也支持应用快速重启(restart)。详情参考下面的[章节 20,开发者工具](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools)和[“How-to”](../IX. ‘How-to’ guides/README.md)章节。
diff --git a/III. Using Spring Boot/19.5. Hot swapping.md b/III. Using Spring Boot/19.5. Hot swapping.md
deleted file mode 100644
index b5a8f9b0..00000000
--- a/III. Using Spring Boot/19.5. Hot swapping.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 19.5. 热交换
-
-由于Spring Boot应用只是普通的Java应用,所以JVM热交换(hot-swapping)也能开箱即用。不过JVM热交换能替换的字节码有限制,想要更彻底的解决方案可以使用[JRebel](http://zeroturnaround.com/software/jrebel/)。`spring-boot-devtools`模块也支持应用快速重启(restart)。
-
-详情参考下面的[Chapter 20, Developer tools](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools)和[“How-to”](../IX. ‘How-to’ guides/README.md)章节。
diff --git a/III. Using Spring Boot/20. Developer Tools.md b/III. Using Spring Boot/20. Developer Tools.md
new file mode 100644
index 00000000..28ad3c7b
--- /dev/null
+++ b/III. Using Spring Boot/20. Developer Tools.md
@@ -0,0 +1,23 @@
+### 20. 开发者工具
+
+Spring Boot包含了一些额外的工具集,用于提升Spring Boot应用的开发体验。`spring-boot-devtools`模块可以included到任何模块中,以提供development-time特性,你只需将该模块的依赖添加到构建中:
+
+**Maven**
+```xml
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ true
+
+
+```
+**Gradle**
+```properties
+dependencies {
+ compile("org.springframework.boot:spring-boot-devtools")
+}
+```
+**注** 在运行一个完整的,打包过的应用时,开发者工具(devtools)会被自动禁用。如果应用使用`java -jar`或特殊的类加载器启动,都会被认为是一个产品级的应用(production application),从而禁用开发者工具。为了防止devtools传递到项目中的其他模块,设置该依赖级别为optional是个不错的实践。不过Gradle不支持`optional`依赖,所以你可能要了解下[propdeps-plugin](https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin)。
+
+**注** 重新打包的归档文件默认不包含开发者工具。如果你想使用某些远程的开发者工具特性,你需要禁用`excludeDevtools`构建属性。Maven和Gradle都支持该属性。
diff --git a/III. Using Spring Boot/20. Developer tools.md b/III. Using Spring Boot/20. Developer tools.md
deleted file mode 100644
index d26286f5..00000000
--- a/III. Using Spring Boot/20. Developer tools.md
+++ /dev/null
@@ -1,20 +0,0 @@
-###20. 开发者工具
-Spring Boot包含了一些额外的工具集,用于提升Spring Boot应用的开发体验。`spring-boot-devtools`模块可以included到任何模块中,以提供development-time特性,你只需简单的将该模块的依赖添加到构建中:
-
-**Maven**
-```xml
-
-
- org.springframework.boot
- spring-boot-devtools
- true
-
-
-```
-**Gradle**
-```properties
-dependencies {
- compile("org.springframework.boot:spring-boot-devtools")
-}
-```
-**注** 在运行一个完整的,打包过的应用时,开发者工具(devtools)会被自动禁用。如果应用使用`java -jar`或特殊的类加载器启动,都会被认为是一个产品级的应用(production application),从而禁用开发者工具。为了防止devtools传递到项目中的其他模块,设置该依赖级别为optional是个不错的实践。不过Gradle不支持`optional`依赖,所以你可能要了解下[propdeps-plugin](https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin)。重新打包的归档文件默认不包含开发者工具。如果你想使用某些远程的开发者工具特性,你需要禁用`excludeDevtools`构建属性。Maven和Gradle都支持该属性。
diff --git a/III. Using Spring Boot/20.1. Property Defaults.md b/III. Using Spring Boot/20.1. Property Defaults.md
new file mode 100644
index 00000000..1fa55953
--- /dev/null
+++ b/III. Using Spring Boot/20.1. Property Defaults.md
@@ -0,0 +1,7 @@
+### 20.1 默认属性
+
+Spring Boot支持的一些库使用缓存提高性能,比如模板引擎将缓存编译完的模板以避免重复解析模板文件。另外,当服务静态资源时,Spring MVC能够加入HTTP缓存头来进行回应。
+虽然缓存在产品中很有用,但开发期间就是个累赘了,因为缓存会阻碍你看到在应用中刚刚做出的修改。正是因为这个原因,`spring-boot-devtools`默认禁用那些缓存选项。
+缓存选项通常配置在`application.properties`文件中,比如Thymeleaf提供了`spring.thymeleaf.cache`属性,`spring-boot-devtools`模块会自动应用敏感的`development-time`配置,而不是手动设置这些属性。
+
+**注** 查看[DevToolsPropertyDefaultsPostProcessor](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java)获取完整的被应用的属性列表。
diff --git a/III. Using Spring Boot/20.1. Property defaults.md b/III. Using Spring Boot/20.1. Property defaults.md
deleted file mode 100644
index 3b8812a0..00000000
--- a/III. Using Spring Boot/20.1. Property defaults.md
+++ /dev/null
@@ -1,6 +0,0 @@
-###20.1 默认属性
-
-Spring Boot支持的一些库使用缓存提高性能,比如模板引擎将缓存编译完的模板以避免重复解析模板文件。另外,当服务静态资源时,Spring MVC能够加入HTTP缓存头来进行回应。虽然缓存在产品中很有用,但开发期间就是个累赘了,因为缓存会阻碍你看到在应用中刚刚做出的修改。正是因为这个原因,`spring-boot-devtools`将会默认禁用那些缓存选项。
-缓存选项通常配置在`application.properties`文件中,比如Thymeleaf提供了`spring.thymeleaf.cache`属性,`spring-boot-devtools`模块会自动应用敏感的`development-time`配置,而不是手动设置这些属性。
-
-**注** 查看[DevToolsPropertyDefaultsPostProcessor](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/env/DevToolsPropertyDefaultsPostProcessor.java)获取完整的被应用的属性列表。
diff --git a/III. Using Spring Boot/20.2. Automatic Restart.md b/III. Using Spring Boot/20.2. Automatic Restart.md
new file mode 100644
index 00000000..3272682b
--- /dev/null
+++ b/III. Using Spring Boot/20.2. Automatic Restart.md
@@ -0,0 +1,19 @@
+### 20.2 自动重启
+
+如果应用使用`spring-boot-devtools`,则只要classpath下的文件有变动,它就会自动重启。这在使用IDE时非常有用,因为可以很快得到代码改变的反馈。默认情况下,classpath下任何指向文件夹的实体都会被监控,注意一些资源的修改比如静态assets,视图模板不需要重启应用。
+
+**触发重启** 由于DevTools监控classpath下的资源,所以唯一触发重启的方式就是更新classpath。引起classpath更新的方式依赖于你使用的IDE,在Eclipse里,保存一个修改的文件会引起classpath更新,并触发重启。在IntelliJ IDEA中,构建工程(Build → Make Project)有同样效果。
+
+**注** 只要开启了fork功能,你也可以通过支持的构建工具(Maven和Gradle)启动应用。因为DevTools需要一个隔离的应用类加载器执行正确的操作。当发现类路径中存在DevTools时,Gradle和Maven会默认执行该行为。
+
+自动重启跟LiveReload可以一起很好的工作,具体参考[LiveReload章节](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-livereload)。如果你使用JRebel,自动重启会被禁用以支持动态类加载,其他devtools特性(比如,LiveReload和属性覆盖)仍旧可以使用。
+
+DevTools依赖应用上下文的shutdown钩子来关闭处于重启过程的应用,如果禁用shutdown钩子(`SpringApplication.setRegisterShutdownHook(false)`),它将不能正常工作。
+
+当判定classpath下实体的改变是否会触发重启时,DevTools自动忽略以下工程:`spring-boot`,`spring-boot-devtools`,`spring-boot-autoconfigure`,`spring-boot-actuator`和`spring-boot-starter`。
+
+DevTools需要自定义`ApplicationContext`使用的资源加载器。如果你的应用已经提供了一个,它将会被覆盖。直接覆盖`ApplicationContext`的getResource方法不被支持。
+
+**Restart vs Reload** Spring Boot提供的重启技术是通过使用两个类加载器实现的。没有变化的类(比如那些第三方jars)会加载进一个基础的类加载器,正在开发的类会加载进一个重启的类加载器。当应用重启时,重启的类加载器会被丢弃,并创建一个新的。这种方式意味着应用重启通常比冷启动快很多,因为基础类加载器已经可用并且填充完成。
+
+如果发现重启对于你的应用来说不够快,或遇到类加载的问题,那你可以考虑reload技术,比如[JRebel](http://zeroturnaround.com/software/jrebel/),这些技术是通过重写它们加载过的类实现的。
diff --git a/III. Using Spring Boot/20.2. Automatic restart.md b/III. Using Spring Boot/20.2. Automatic restart.md
deleted file mode 100644
index 5a88550f..00000000
--- a/III. Using Spring Boot/20.2. Automatic restart.md
+++ /dev/null
@@ -1,20 +0,0 @@
-###20.2 自动重启
-
-如果应用使用`spring-boot-devtools`,则只要classpath下的文件有变动,它就会自动重启。这在使用IDE时非常有用,因为可以很快得到代码改变的反馈。默认情况下,classpath下任何指向文件夹的实体都会被监控,注意一些资源的修改比如静态assets,视图模板不需要重启应用。
-
-**触发重启** 由于DevTools监控classpath下的资源,所以唯一触发重启的方式就是更新classpath。引起classpath更新的方式依赖于你使用的IDE,在Eclipse里,保存一个修改的文件将引起classpath更新,并触发重启。在IntelliJ IDEA中,构建工程(Build → Make Project)有同样效果。
-
-**注** 你也可以通过支持的构建工具(比如,Maven和Gradle)启动应用,只要开启fork功能,因为DevTools需要一个隔离的应用类加载器执行正确的操作。当发现类路径中存在DevTools时,Gradle和Maven会默认执行该行为,
-
-自动重启跟LiveReload可以一起很好的工作,具体参考[下面章节](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-livereload)。如果你使用JRebel,自动重启将禁用以支持动态类加载,其他devtools特性,比如LiveReload,属性覆盖仍旧可以使用。
-
-DevTools依赖应用上下文的shutdown钩子来关闭处于重启过程的应用,如果禁用shutdown钩子(`SpringApplication.setRegisterShutdownHook(false)`),它将不能正常工作。
-
-当判定classpath下实体的改变是否会触发重启时,DevTools自动忽略以下工程:`spring-boot`,`spring-boot-devtools`,`spring-boot-autoconfigure`,`spring-boot-actuator`和`spring-boot-starter`。
-
-DevTools需要自定义`ApplicationContext`使用的资源加载器。如果你的应用已经提供了一个,它将会被覆盖。直接覆盖`ApplicationContext`的getResource方法不被支持。
-
-**Restart vs Reload** Spring Boot提供的重启技术是通过使用两个类加载器实现的。没有变化的类(比如那些第三方jars)会加载进一个基础(basic)classloader,正在开发的类会加载进一个重启(restart)classloader。当应用重启时,restart类加载器会被丢弃,并创建一个新的。这种方式意味着应用重启通常比冷启动(cold starts)快很多,因为基础类加载器已经可用,并且populated(意思是基础类加载器加载的类比较多?)。
-
-如果发现重启对于你的应用来说不够快,或遇到类加载的问题,那你可以考虑reload技术,比如[JRebel](http://zeroturnaround.com/software/jrebel/),这些技术是通过重写它们加载过的类实现的。
-
diff --git a/III. Using Spring Boot/20.2.1. Excluding resources.md b/III. Using Spring Boot/20.2.1. Excluding resources.md
deleted file mode 100644
index 41d7ca5d..00000000
--- a/III. Using Spring Boot/20.2.1. Excluding resources.md
+++ /dev/null
@@ -1,8 +0,0 @@
-### 20.2.1 排除资源
-
-某些资源的变化没必要触发重启,比如Thymeleaf模板可以随时编辑。默认情况下,位于`/META-INF/maven`,`/META-INF/resources`,`/resources`,`/static`,`/public`或`/templates`下的资源变更不会触发重启,但会触发实时加载(live reload)。你可以使用`spring.devtools.restart.exclude`属性自定义这些排除规则,比如,为了只排除`/static`和`/public`,你可以这样设置:
-```properties
-spring.devtools.restart.exclude=static/**,public/**
-```
-
-**注** 如果你想保留默认属性,并添加其他的排除规则,可以使用`spring.devtools.restart.additional-exclude`属性作为代替。
diff --git a/III. Using Spring Boot/20.2.1. Logging changes in condition evaluation.md b/III. Using Spring Boot/20.2.1. Logging changes in condition evaluation.md
new file mode 100644
index 00000000..ffb89675
--- /dev/null
+++ b/III. Using Spring Boot/20.2.1. Logging changes in condition evaluation.md
@@ -0,0 +1,8 @@
+### 20.2.1 在状况评估里记录更改
+
+默认地,每次应用重启,都会记录一份展示状况评估差量的报告。报告展示了对应用的自动配置所做的更改,比如添加或者移除bean、设置配置属性。
+
+禁用记录报告,设置以下属性:
+```properties
+spring.devtools.restart.log-condition-evaluation-delta=false
+```
\ No newline at end of file
diff --git a/III. Using Spring Boot/20.2.2. Excluding Resources.md b/III. Using Spring Boot/20.2.2. Excluding Resources.md
new file mode 100644
index 00000000..0ae04c9f
--- /dev/null
+++ b/III. Using Spring Boot/20.2.2. Excluding Resources.md
@@ -0,0 +1,8 @@
+### 20.2.2 排除资源
+
+某些资源的变化没必要触发重启,比如Thymeleaf模板可以随时编辑。默认情况下,位于`/META-INF/maven`,`/META-INF/resources`,`/resources`,`/static`,`/public`或`/templates`下的资源变更不会触发重启,但会触发实时重载(live reload)。你可以使用`spring.devtools.restart.exclude`属性自定义这些排除规则,比如,为了只排除`/static`和`/public`,你可以设置如下属性:
+```properties
+spring.devtools.restart.exclude=static/**,public/**
+```
+
+**注** 如果你想保留默认属性,并添加其他的排除规则,可以使用`spring.devtools.restart.additional-exclude`属性作为代替。
diff --git a/III. Using Spring Boot/20.2.2. Watching additional paths.md b/III. Using Spring Boot/20.2.2. Watching additional paths.md
deleted file mode 100644
index b2145a57..00000000
--- a/III. Using Spring Boot/20.2.2. Watching additional paths.md
+++ /dev/null
@@ -1,3 +0,0 @@
-###20.2.2 查看其他路径
-
-如果想让应用在改变没有位于classpath下的文件时也会重启或重新加载,你可以使用`spring.devtools.restart.additional-paths`属性来配置监控变化的额外路径。你可以使用[上面描述](./20.2.1 Excluding resources.md)过的`spring.devtools.restart.exclude`属性去控制额外路径下的变化是否触发一个完整重启或只是一个实时重新加载。
diff --git a/III. Using Spring Boot/20.2.3. Disabling restart.md b/III. Using Spring Boot/20.2.3. Disabling restart.md
deleted file mode 100644
index fe0e1796..00000000
--- a/III. Using Spring Boot/20.2.3. Disabling restart.md
+++ /dev/null
@@ -1,11 +0,0 @@
-###20.2.3 禁用重启
-
-如果不想使用重启特性,你可以通过`spring.devtools.restart.enabled`属性来禁用它,通常情况下可以在`application.properties`文件中设置(依旧会初始化重启类加载器,但它不会监控文件变化)。
-
-如果需要彻底禁用重启支持,比如,不能跟某个特殊库一块工作,你需要在调用`SpringApplication.run(…)`之前设置一个系统属性,如下:
-```java
-public static void main(String[] args) {
- System.setProperty("spring.devtools.restart.enabled", "false");
- SpringApplication.run(MyApp.class, args);
-}
-```
diff --git a/III. Using Spring Boot/20.2.3. Watching Additional Paths.md b/III. Using Spring Boot/20.2.3. Watching Additional Paths.md
new file mode 100644
index 00000000..dda43811
--- /dev/null
+++ b/III. Using Spring Boot/20.2.3. Watching Additional Paths.md
@@ -0,0 +1,3 @@
+### 20.2.3 查看其他路径
+
+如果想让应用在改变没有位于classpath下的文件时也会重启或重新加载,你可以使用`spring.devtools.restart.additional-paths`属性来配置监控变化的额外路径。你可以使用[之前描述](./20.2.2 Excluding Resources.md)过的`spring.devtools.restart.exclude`属性去控制额外路径下的变化是否触发一个完整重启或一个实时重新加载。
diff --git a/III. Using Spring Boot/20.2.4. Disabling Restart.md b/III. Using Spring Boot/20.2.4. Disabling Restart.md
new file mode 100644
index 00000000..56aefed9
--- /dev/null
+++ b/III. Using Spring Boot/20.2.4. Disabling Restart.md
@@ -0,0 +1,11 @@
+### 20.2.4 禁用重启
+
+如果不想使用重启特性,你可以通过`spring.devtools.restart.enabled`属性来禁用它。通常情况下可以在`application.properties`文件中设置(依旧会初始化重启类加载器,但它不会监控文件变化)。
+
+如果需要彻底禁用重启支持(比如,不能跟某个特殊库一块工作),你需要在调用`SpringApplication.run(…)`之前,把系统属性`spring.devtools.restart.enabled`设置为`false`,如下:
+```java
+public static void main(String[] args) {
+ System.setProperty("spring.devtools.restart.enabled", "false");
+ SpringApplication.run(MyApp.class, args);
+}
+```
diff --git a/III. Using Spring Boot/20.2.4. Using a trigger file.md b/III. Using Spring Boot/20.2.4. Using a trigger file.md
deleted file mode 100644
index 4bc94c30..00000000
--- a/III. Using Spring Boot/20.2.4. Using a trigger file.md
+++ /dev/null
@@ -1,7 +0,0 @@
-###20.2.4 使用触发器文件
-
-如果使用一个IDE连续不断地编译变化的文件,你可能倾向于只在特定时间触发重启,触发器文件可以帮你实现该功能。触发器文件是一个特殊的文件,只有修改它才能实际触发一个重启检测。改变该文件只会触发检测,实际的重启只会在Devtools发现它必须这样做的时候,触发器文件可以手动更新,也可以通过IDE插件更新。
-
-使用`spring.devtools.restart.trigger-file`属性可以指定触发器文件。
-
-**注** 你可能想将`spring.devtools.restart.trigger-file`属性设置为[全局设置](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools-globalsettings),这样所有的工程表现都会相同。
diff --git a/III. Using Spring Boot/20.2.5. Customizing the restart classloader.md b/III. Using Spring Boot/20.2.5. Customizing the restart classloader.md
deleted file mode 100644
index 2e8bf124..00000000
--- a/III. Using Spring Boot/20.2.5. Customizing the restart classloader.md
+++ /dev/null
@@ -1,12 +0,0 @@
-###20.2.5 自定义restart类加载器
-
-正如以上[Restart vs Reload](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-spring-boot-restart-vs-reload)章节讨论的,重启功能是通过两个类加载器实现的。对于大部分应用来说是没问题的,但有时候它可能导致类加载问题。
-
-默认情况,在IDE里打开的项目会通过'restart'类加载器加载,其他常规的`.jar`文件会使用'basic'类加载器加载。如果你工作在一个多模块的项目下,并且不是每个模块都导入IDE里,你可能需要自定义一些东西。你需要创建一个`META-INF/spring-devtools.properties`文件,`spring-devtools.properties`文件可以包含`restart.exclude.`,`restart.include.`前缀的属性。`include`元素定义了那些需要加载进'restart'类加载器中的实体,`exclude`元素定义了那些需要加载进'basic'类加载器中的实体,这些属性的值是一个将应用到classpath的正则表达式。
-
-例如:
-```properties
-restart.include.companycommonlibs=/mycorp-common-[\\w-]+\.jar
-restart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jar
-```
-**注** 所有属性的keys必须唯一,只要以`restart.include.`或`restart.exclude.`开头都会考虑进去。所有来自classpath的`META-INF/spring-devtools.properties`都会被加载,你可以将文件打包进工程或工程使用的库里。
diff --git a/III. Using Spring Boot/20.2.5. Using a Trigger File.md b/III. Using Spring Boot/20.2.5. Using a Trigger File.md
new file mode 100644
index 00000000..ff9d4f6d
--- /dev/null
+++ b/III. Using Spring Boot/20.2.5. Using a Trigger File.md
@@ -0,0 +1,7 @@
+### 20.2.5 使用触发器文件
+
+如果使用一个IDE连续不断地编译变化的文件,你可能倾向于只在特定时间触发重启,触发器文件可以帮你实现该功能。触发器文件是一个特殊的文件,只有修改它才能实际触发一个重启检测。改变该文件只会触发检测,实际的重启只会在Devtools发现它必须这样做的时候。触发器文件可以手动更新,也可以通过IDE插件更新。
+
+为了使用触发器文件,把`spring.devtools.restart.trigger-file`属性设置为你的触发器文件的路径。
+
+**注** 你可能想将`spring.devtools.restart.trigger-file`属性设置为[全局设置](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#using-boot-devtools-globalsettings),这样所有的工程表现都会相同。
diff --git a/III. Using Spring Boot/20.2.6. Customizing the Restart Classloader.md b/III. Using Spring Boot/20.2.6. Customizing the Restart Classloader.md
new file mode 100644
index 00000000..32a16242
--- /dev/null
+++ b/III. Using Spring Boot/20.2.6. Customizing the Restart Classloader.md
@@ -0,0 +1,12 @@
+### 20.2.6 自定义restart类加载器
+
+正如之前[Restart vs Reload](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#using-spring-boot-restart-vs-reload)章节讨论的,重启功能是通过两个类加载器实现的。对于大部分应用来说是没问题的,但有时候它可能导致类加载问题。
+
+默认情况,在IDE里打开的项目会通过'restart'类加载器加载,其他常规的`.jar`文件会使用'basic'类加载器加载。如果你工作在一个多模块的项目下,并且不是每个模块都导入IDE里,你可能需要自定义一些东西。你需要创建一个`META-INF/spring-devtools.properties`文件,`spring-devtools.properties`文件可以包含`restart.exclude.`,`restart.include.`前缀的属性。`include`元素定义了那些需要加载进'restart'类加载器中的实体,`exclude`元素定义了那些需要加载进'basic'类加载器中的实体,这些属性的值是一个将应用到classpath的正则表达式。例如:
+```properties
+restart.include.companycommonlibs=/mycorp-common-[\\w-]+\.jar
+restart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jar
+```
+**注** 所有属性的keys必须唯一,只要以`restart.include.`或`restart.exclude.`开头都会考虑进去。
+
+**注** 所有来自classpath的`META-INF/spring-devtools.properties`都会被加载,你可以将文件打包进工程或工程使用的库里。
diff --git a/III. Using Spring Boot/20.2.6. Known limitations.md b/III. Using Spring Boot/20.2.6. Known limitations.md
deleted file mode 100644
index b7a4e045..00000000
--- a/III. Using Spring Boot/20.2.6. Known limitations.md
+++ /dev/null
@@ -1,5 +0,0 @@
-###20.2.6 已知限制
-
-重启功能不能跟使用标准`ObjectInputStream`反序列化的对象工作,如果需要反序列化数据,你可能需要使用Spring的`ConfigurableObjectInputStream`,并结合`Thread.currentThread().getContextClassLoader()`。
-
-不幸的是,一些第三方库反序列化时没有考虑上下文类加载器,如果发现这样的问题,你需要请求原作者给处理下。
diff --git a/III. Using Spring Boot/20.2.7. Known Limitations.md b/III. Using Spring Boot/20.2.7. Known Limitations.md
new file mode 100644
index 00000000..d27a5d0c
--- /dev/null
+++ b/III. Using Spring Boot/20.2.7. Known Limitations.md
@@ -0,0 +1,5 @@
+### 20.2.7 已知限制
+
+重启功能不能跟使用标准`ObjectInputStream`反序列化的对象工作,如果需要反序列化数据,你可能需要使用Spring的`ConfigurableObjectInputStream`,并结合`Thread.currentThread().getContextClassLoader()`。
+
+不幸的是,一些第三方库反序列化时没有考虑上下文类加载器,如果发现这样的问题,你需要请求原作者给处理下。
diff --git a/III. Using Spring Boot/20.3. LiveReload.md b/III. Using Spring Boot/20.3. LiveReload.md
index e9be8d28..d83c6ddc 100644
--- a/III. Using Spring Boot/20.3. LiveReload.md
+++ b/III. Using Spring Boot/20.3. LiveReload.md
@@ -1,7 +1,7 @@
-###20.3 LiveReload
+### 20.3 LiveReload
`spring-boot-devtools`模块包含一个内嵌的LiveReload服务器,它可以在资源改变时触发浏览器刷新。LiveReload浏览器扩展可以免费从[livereload.com](http://livereload.com/extensions/)站点获取,支持Chrome,Firefox,Safari等浏览器。
如果不想在运行应用时启动LiveReload服务器,你可以将`spring.devtools.livereload.enabled`属性设置为false。
-**注** 每次只能运行一个LiveReload服务器。在启动应用之前,确保没有其它的LiveReload服务器正在运行。如果你在IDE中启动多个应用,只有第一个能够获得动态加载功能。
+**注** 每次只能运行一个LiveReload服务器。在启动应用之前,确保没有其它的LiveReload服务器正在运行。如果你在IDE中启动多个应用,只有第一个能够获得动态重载功能。
diff --git a/III. Using Spring Boot/20.4. Global Settings.md b/III. Using Spring Boot/20.4. Global Settings.md
new file mode 100644
index 00000000..9f38d0f4
--- /dev/null
+++ b/III. Using Spring Boot/20.4. Global Settings.md
@@ -0,0 +1,8 @@
+### 20.4 全局设置
+
+在`$HOME`文件夹下添加一个`.spring-boot-devtools.properties`的文件可以用来配置全局的devtools设置(注意文件名以"."开头),添加进该文件的任何属性都会应用到你机器上使用该devtools的Spring Boot应用。例如,想使用触发器文件进行重启,可以添加如下属性:
+
+**~/.spring-boot-devtools.properties.**
+```properties
+spring.devtools.reload.trigger-file=.reloadtrigger
+```
diff --git a/III. Using Spring Boot/20.4. Global settings.md b/III. Using Spring Boot/20.4. Global settings.md
deleted file mode 100644
index f1dfe24a..00000000
--- a/III. Using Spring Boot/20.4. Global settings.md
+++ /dev/null
@@ -1,8 +0,0 @@
-###20.4 全局设置
-
-在`$HOME`文件夹下添加一个`.spring-boot-devtools.properties`的文件可以用来配置全局的devtools设置(注意文件名以"."开头),添加进该文件的任何属性都会应用到你机器上使用该devtools的Spring Boot应用。例如,想使用触发器文件进行重启,可以添加如下配置:
-
-~/.spring-boot-devtools.properties.
-```properties
-spring.devtools.reload.trigger-file=.reloadtrigger
-```
diff --git a/III. Using Spring Boot/20.5. Remote Applications.md b/III. Using Spring Boot/20.5. Remote Applications.md
new file mode 100644
index 00000000..6446aa43
--- /dev/null
+++ b/III. Using Spring Boot/20.5. Remote Applications.md
@@ -0,0 +1,23 @@
+### 20.5 远程应用
+
+Spring Boot开发者工具并不仅限于本地开发,在运行远程应用时你也可以使用一些特性。远程支持是可选的。启用远程支持,你需要确保开发者工具被包含在重新打包的归档文件中。
+```properties
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ false
+
+
+
+
+```
+之后,你需要通过设置`spring.devtools.remote.secret`属性启用它,例如:
+```properties
+spring.devtools.remote.secret=mysecret
+```
+**注** 在远程应用上启用`spring-boot-devtools`有一定的安全风险,生产环境中最好不要使用。
+
+远程devtools支持分两部分:一个是接收连接的服务端端点,另一个是运行在IDE里的客户端应用。如果设置`spring.devtools.remote.secret`属性,服务端组件会自动启用,客户端组件必须手动启动。
diff --git a/III. Using Spring Boot/20.5. Remote applications.md b/III. Using Spring Boot/20.5. Remote applications.md
deleted file mode 100644
index c6b686b9..00000000
--- a/III. Using Spring Boot/20.5. Remote applications.md
+++ /dev/null
@@ -1,23 +0,0 @@
-###20.5 远程应用
-
-Spring Boot开发者工具并不仅限于本地开发,在运行远程应用时你也可以使用一些特性。远程支持是可选的,你需要确保开发者工具被包含在重新打包的归档文件中。
-```properties
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
- false
-
-
-
-
-```
-之后,你需要通过设置`spring.devtools.remote.secret`属性启用它,例如:
-```properties
-spring.devtools.remote.secret=mysecret
-```
-**注** 在远程应用上启用`spring-boot-devtools`有一定的安全风险,生产环境中最好不要使用。
-
-远程devtools支持分两部分:一个是接收连接的服务端端点,另一个是运行在IDE里的客户端应用。如果设置`spring.devtools.remote.secret`属性,服务端组件会自动启用,客户端组件必须手动启动。
diff --git a/III. Using Spring Boot/20.5.1. Running the Remote Client Application.md b/III. Using Spring Boot/20.5.1. Running the Remote Client Application.md
new file mode 100644
index 00000000..27d01a68
--- /dev/null
+++ b/III. Using Spring Boot/20.5.1. Running the Remote Client Application.md
@@ -0,0 +1,31 @@
+### 20.5.1 运行远程客户端应用
+
+远程客户端应用程序(remote client application)需要在你的IDE中运行。你需要使用跟将要连接的远程应用相同的classpath运行`org.springframework.boot.devtools.RemoteSpringApplication`。应用需要的唯一一个参数是你要连接的远程应用URL。例如,你正在使用Eclipse或STS,并有一个部署到Cloud Foundry的`my-app`工程,远程连接该应用需要做以下操作:
+* 从`Run`菜单选择`Run Configurations…`。
+* 创建一个新的`Java Application`启动配置(launch configuration)。
+* 浏览`my-app`工程。
+* 将`org.springframework.boot.devtools.RemoteSpringApplication`作为main类。
+* 将`https://myapp.cfapps.io`作为参数传递给`RemoteSpringApplication`(或其他任何远程URL)。
+
+运行中的远程客户端看起来如下:
+```
+ . ____ _ __ _ _
+ /\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
+( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \
+ \\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) )
+ ' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / /
+ =========|_|==============|___/===================================/_/_/_/
+ :: Spring Boot Remote :: 2.0.0.RELEASE
+
+2015-06-10 18:25:06.632 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code/spring-boot-samples/spring-boot-sample-devtools)
+2015-06-10 18:25:06.671 INFO 14938 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
+2015-06-10 18:25:07.043 WARN 14938 --- [ main] o.s.b.d.r.c.RemoteClientConfiguration : The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
+2015-06-10 18:25:07.074 INFO 14938 --- [ main] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
+2015-06-10 18:25:07.130 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)
+```
+
+**注** 因为远程客户端使用的classpath跟真实应用相同,所以它能直接读取应用配置,这就是`spring.devtools.remote.secret`如何被读取和传递给服务器做验证的。
+
+强烈建议使用`https://`作为连接协议,这样传输通道是加密的,密码也不会被截获。
+
+如果需要使用代理连接远程应用,你需要配置`spring.devtools.remote.proxy.host`和`spring.devtools.remote.proxy.port`属性。
diff --git a/III. Using Spring Boot/20.5.1. Running the remote client application.md b/III. Using Spring Boot/20.5.1. Running the remote client application.md
deleted file mode 100644
index f205a9ca..00000000
--- a/III. Using Spring Boot/20.5.1. Running the remote client application.md
+++ /dev/null
@@ -1,31 +0,0 @@
-###20.5.1 运行远程客户端应用
-远程客户端应用程序(remote client application)需要在你的IDE中运行,你需要使用跟将要连接的远程应用相同的classpath运行`org.springframework.boot.devtools.RemoteSpringApplication`,传参为你要连接的远程应用URL。例如,你正在使用Eclipse或STS,并有一个部署到Cloud Foundry的`my-app`工程,远程连接该应用需要做以下操作:
-* 从`Run`菜单选择`Run Configurations…`。
-* 创建一个新的`Java Application`启动配置(launch configuration)。
-* 浏览`my-app`工程。
-* 将`org.springframework.boot.devtools.RemoteSpringApplication`作为main类。
-* 将`https://myapp.cfapps.io`作为参数传递给`RemoteSpringApplication`(或其他任何远程URL)。
-
-运行中的远程客户端看起来如下:
-```shell
- . ____ _ __ _ _
- /\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
-( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \
- \\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) )
- ' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / /
- =========|_|==============|___/===================================/_/_/_/
- :: Spring Boot Remote :: 2.0.0.M5
-
-2015-06-10 18:25:06.632 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code/spring-boot-samples/spring-boot-sample-devtools)
-2015-06-10 18:25:06.671 INFO 14938 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
-2015-06-10 18:25:07.043 WARN 14938 --- [ main] o.s.b.d.r.c.RemoteClientConfiguration : The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
-2015-06-10 18:25:07.074 INFO 14938 --- [ main] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
-2015-06-10 18:25:07.130 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)
-```
-
-**注** 因为远程客户端使用的classpath跟真实应用相同,所以它能直接读取应用配置,这就是`spring.devtools.remote.secret`如何被读取和传递给服务器做验证的。
-
-强烈建议使用`https://`作为连接协议,这样传输通道是加密的,密码也不会被截获。
-
-如果需要使用代理连接远程应用,你需要配置`spring.devtools.remote.proxy.host`和`spring.devtools.remote.proxy.port`属性。
-
diff --git a/III. Using Spring Boot/20.5.2. Remote Update.md b/III. Using Spring Boot/20.5.2. Remote Update.md
new file mode 100644
index 00000000..d9bf0017
--- /dev/null
+++ b/III. Using Spring Boot/20.5.2. Remote Update.md
@@ -0,0 +1,5 @@
+### 20.5.2 远程更新
+
+远程客户端将监听应用的classpath变化。任何更新的资源都会发布到远程应用,并触发重启。这在你使用云服务迭代某个特性时非常有用。通常远程更新和重启比完整rebuild和deploy快多了。
+
+**注** 文件只有在远程客户端运行时才监控。如果你在启动远程客户端之前改变一个文件,它是不会被发布到远程server的。
diff --git a/III. Using Spring Boot/20.5.2. Remote update.md b/III. Using Spring Boot/20.5.2. Remote update.md
deleted file mode 100644
index 6c3b7f69..00000000
--- a/III. Using Spring Boot/20.5.2. Remote update.md
+++ /dev/null
@@ -1,4 +0,0 @@
-###20.5.2 远程更新
-远程客户端将监听应用的classpath变化,任何更新的资源都会发布到远程应用,并触发重启,这在你使用云服务迭代某个特性时非常有用。通常远程更新和重启比完整rebuild和deploy快多了。
-
-**注** 文件只有在远程客户端运行时才监控。如果你在启动远程客户端之前改变一个文件,它是不会被发布到远程server的。
diff --git a/III. Using Spring Boot/21. Packaging your application for production.md b/III. Using Spring Boot/21. Packaging Your Application for Production.md
similarity index 100%
rename from III. Using Spring Boot/21. Packaging your application for production.md
rename to III. Using Spring Boot/21. Packaging Your Application for Production.md
diff --git a/III. Using Spring Boot/22. What to Read Next.md b/III. Using Spring Boot/22. What to Read Next.md
new file mode 100644
index 00000000..79f7e020
--- /dev/null
+++ b/III. Using Spring Boot/22. What to Read Next.md
@@ -0,0 +1,3 @@
+### 22. 接下来阅读什么
+
+现在你应该明白怎么结合最佳实践使用Spring Boot,接下来可以深入学习特殊的部分[Spring Boot特性](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features),或者你可以跳过开头,阅读Spring Boot的[production ready](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#production-ready)部分。
diff --git a/III. Using Spring Boot/22. What to read next.md b/III. Using Spring Boot/22. What to read next.md
deleted file mode 100644
index 196f025d..00000000
--- a/III. Using Spring Boot/22. What to read next.md
+++ /dev/null
@@ -1,2 +0,0 @@
-### 22. 接下来阅读什么
-现在你应该明白怎么结合最佳实践使用Spring Boot,接下来可以深入学习特殊的部分[Spring Boot features](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features),或者你可以跳过开头,阅读Spring Boot的[production ready](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#production-ready)部分。
diff --git a/IV. Spring Boot features/23. SpringApplication.md b/IV. Spring Boot features/23. SpringApplication.md
index 6f53dc15..da829b86 100644
--- a/IV. Spring Boot features/23. SpringApplication.md
+++ b/IV. Spring Boot features/23. SpringApplication.md
@@ -1,5 +1,6 @@
-###23. SpringApplication
-SpringApplication类提供了一种快捷方式,用于从`main()`方法启动Spring应用。多数情况下,你只需要将该任务委托给`SpringApplication.run`静态方法:
+### 23. SpringApplication
+
+SpringApplication类提供了一种快捷方式,用于从`main()`方法启动Spring应用。多数情况下,你可以将该任务委托给`SpringApplication.run`静态方法:
```java
public static void main(String[] args){
SpringApplication.run(MySpringConfiguration.class, args);
@@ -13,11 +14,11 @@ public static void main(String[] args){
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
- :: Spring Boot :: v2.0.0.M5
+ :: Spring Boot :: v2.0.0.RELEASE
2013-07-31 00:08:16.117 INFO 56603 --- [ main] o.s.b.s.app.SampleApplication : Starting SampleApplication v0.1.0 on mycomputer with PID 56603 (/apps/myapp.jar started by pwebb)
2013-07-31 00:08:16.166 INFO 56603 --- [ main] ationConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6e5a8246: startup date [Wed Jul 31 00:08:16 PDT 2013]; root of context hierarchy
2014-03-04 13:09:54.912 INFO 41370 --- [ main] .t.TomcatServletWebServerFactory : Server initialized with port: 8080
2014-03-04 13:09:56.501 INFO 41370 --- [ main] o.s.b.s.app.SampleApplication : Started SampleApplication in 2.992 seconds (JVM running for 3.658)
```
-默认情况下会显示INFO级别的日志信息,包括一些相关的启动详情,比如启动应用的用户等。
+默认情况下会显示`INFO`级别的日志信息,包括一些相关的启动详情,比如启动应用的用户等。如果你需要`INFO`之外的日志级别,你可以参考[章节 26.4 日志级别](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-custom-log-levels)进行设置。
diff --git a/IV. Spring Boot features/23.1. Startup Failure.md b/IV. Spring Boot features/23.1. Startup Failure.md
new file mode 100644
index 00000000..15cdde23
--- /dev/null
+++ b/IV. Spring Boot features/23.1. Startup Failure.md
@@ -0,0 +1,24 @@
+### 23.1 启动失败
+
+如果应用启动失败,注册的`FailureAnalyzers`就有机会提供一个特定的错误信息,及具体的解决该问题的动作。例如,如果在`8080`端口启动一个web应用,而该端口已被占用,那你应该可以看到类似如下的信息:
+```properties
+***************************
+APPLICATION FAILED TO START
+***************************
+
+Description:
+
+Embedded servlet container failed to start. Port 8080 was already in use.
+
+Action:
+
+Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
+```
+**注** Spring Boot提供很多的`FailureAnalyzer`实现。你也可以[自己实现](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-failure-analyzer)。
+
+如果没有可用于处理该异常的失败分析器(failure analyzers),你需要展示完整的情况报告以便更好的查看出问题的地方,因此你需要启用`org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener`的[debug](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config)属性,或开启[DEBUG日志级别](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-custom-log-levels)。
+
+例如,使用`java -jar`运行应用时,你可以通过如下命令启用`debug`属性:
+```shell
+$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
+```
diff --git a/IV. Spring Boot features/23.1. Startup failure.md b/IV. Spring Boot features/23.1. Startup failure.md
deleted file mode 100644
index 10532436..00000000
--- a/IV. Spring Boot features/23.1. Startup failure.md
+++ /dev/null
@@ -1,23 +0,0 @@
-###23.1 启动失败
-如果应用启动失败,注册的`FailureAnalyzers`就有机会提供一个特定的错误信息,及具体的解决该问题的动作。例如,如果在`8080`端口启动一个web应用,而该端口已被占用,那你应该可以看到类似如下的内容:
-```properties
-***************************
-APPLICATION FAILED TO START
-***************************
-
-Description:
-
-Embedded servlet container failed to start. Port 8080 was already in use.
-
-Action:
-
-Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
-```
-**注** Spring Boot提供很多的`FailureAnalyzer`实现,你[自己实现](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#howto-failure-analyzer)也很容易。
-
-如果没有可用于处理该异常的失败分析器(failure analyzers),你需要展示完整的auto-configuration报告以便更好的查看出问题的地方,因此你需要启用`org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer`的[debug](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config)属性,或开启[DEBUG日志级别](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-custom-log-levels)。
-
-例如,使用`java -jar`运行应用时,你可以通过如下命令启用`debug`属性:
-```shell
-$ java -jar myproject-0.0.1-SNAPSHOT.jar --debug
-```
diff --git a/IV. Spring Boot features/23.10. Admin Features.md b/IV. Spring Boot features/23.10. Admin Features.md
new file mode 100644
index 00000000..b12d8cb3
--- /dev/null
+++ b/IV. Spring Boot features/23.10. Admin Features.md
@@ -0,0 +1,7 @@
+### 23.10 Admin特性
+
+通过设置`spring.application.admin.enabled`属性可以启用管理相关的(admin-related)特性,这将暴露[SpringApplicationAdminMXBean](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java)到平台的`MBeanServer`,你可以使用该特性远程管理Spring Boot应用。这个特性对任何service包装器(wrapper)实现也有用。
+
+**注** 通过`local.server.port`可以获取该应用运行的HTTP端口。
+
+**警告** 启用该特性时需要注意MBean会暴露一个方法去关闭应用。
diff --git a/IV. Spring Boot features/23.10. Admin features.md b/IV. Spring Boot features/23.10. Admin features.md
deleted file mode 100644
index e9cc1174..00000000
--- a/IV. Spring Boot features/23.10. Admin features.md
+++ /dev/null
@@ -1,6 +0,0 @@
-### 23.10 Admin特性
-
-通过设置`spring.application.admin.enabled`属性可以启用管理相关的(admin-related)特性,这将暴露[SpringApplicationAdminMXBean](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBean.java)到平台的`MBeanServer`,你可以使用该特性远程管理Spring Boot应用,这对任何service包装器(wrapper)实现也有用。
-
-**注** 通过`local.server.port`可以获取该应用运行的HTTP端口。启用该特性时需要注意MBean会暴露一个方法去关闭应用。
-
diff --git a/IV. Spring Boot features/23.2. Customizing the Banner.md b/IV. Spring Boot features/23.2. Customizing the Banner.md
index b249cd64..ef6722a5 100644
--- a/IV. Spring Boot features/23.2. Customizing the Banner.md
+++ b/IV. Spring Boot features/23.2. Customizing the Banner.md
@@ -1,6 +1,6 @@
### 23.2. 自定义Banner
-通过在classpath下添加一个`banner.txt`或设置`banner.location`来指定相应的文件可以改变启动过程中打印的banner。如果这个文件有特殊的编码,你可以使用`banner.encoding`设置它(默认为UTF-8)。除了文本文件,你也可以添加一个`banner.gif`,`banner.jpg`或`banner.png`图片,或设置`banner.image.location`属性。图片会转换为字符画(ASCII art)形式,并在所有文本banner上方显示。
+通过在classpath下添加一个`banner.txt`或设置`spring.banner.location`属性来指定相应的文件,可以改变启动过程中打印的banner。如果这个文件不是以UTF-8编码,你可以设置`spring.banner.charset`。除了文本文件,你也可以添加一个`banner.gif`,`banner.jpg`或`banner.png`图片,或设置`spring.banner.image.location`属性。图片会转换为字符画(ASCII art)形式,并在所有文本banner上方显示。
在banner.txt中可以使用如下占位符:
@@ -8,9 +8,9 @@
| ----------- | :--------|
|${application.version}|MANIFEST.MF中声明的应用版本号,例如`Implementation-Version: 1.0`会打印`1.0`|
|${application.formatted-version}|MANIFEST.MF中声明的被格式化后的应用版本号(被括号包裹且以v作为前缀),用于显示,例如(`v1.0`)|
-|${spring-boot.version}|当前Spring Boot的版本号,例如`2.0.0.M5`|
-|${spring-boot.formatted-version}|当前Spring Boot被格式化后的版本号(被括号包裹且以v作为前缀), 用于显示,例如(`v2.0.0.M5`)|
-|${Ansi.NAME}(或${AnsiColor.NAME},${AnsiBackground.NAME}, ${AnsiStyle.NAME})|NAME代表一种ANSI编码,具体详情查看[AnsiPropertySource](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java)|
+|${spring-boot.version}|当前Spring Boot的版本号,例如`2.0.0.RELEASE`|
+|${spring-boot.formatted-version}|当前Spring Boot被格式化后的版本号(被括号包裹且以v作为前缀), 用于显示,例如(`v2.0.0.RELEASE`)|
+|${Ansi.NAME}(或${AnsiColor.NAME},${AnsiBackground.NAME}, ${AnsiStyle.NAME})|NAME代表一种ANSI编码,具体详情查看[AnsiPropertySource](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot/src/main/java/org/springframework/boot/ansi/AnsiPropertySource.java)|
|${application.title}|`MANIFEST.MF`中声明的应用title,例如`Implementation-Title: MyApp`会打印`MyApp`|
**注** 如果想以编程的方式产生一个banner,可以使用`SpringBootApplication.setBanner(…)`方法,并实现`org.springframework.boot.Banner`接口的`printBanner()`方法。
@@ -19,7 +19,7 @@
打印的banner将注册成一个名为`springBootBanner`的单例bean。
-**注** YAML会将`off`映射为`false`,如果想在应用中禁用banner,你需要确保`off`添加了括号:
+**注** YAML会将`off`映射为`false`,如果想在应用中禁用banner,你需要确保`off`添加了引号:
```json
spring:
main:
diff --git a/IV. Spring Boot features/23.3. Customizing SpringApplication.md b/IV. Spring Boot features/23.3. Customizing SpringApplication.md
index 63033d20..9bd19920 100644
--- a/IV. Spring Boot features/23.3. Customizing SpringApplication.md
+++ b/IV. Spring Boot features/23.3. Customizing SpringApplication.md
@@ -8,6 +8,6 @@ public static void main(String[] args) {
app.run(args);
}
```
-**注**:传递给`SpringApplication`的构造器参数将作为spring beans的配置源,多数情况下,它们是一些`@Configuration`类的引用,但也可能是XML配置或要扫描包的引用。
+**注**:传递给`SpringApplication`的构造器参数将作为Spring bean的配置源,多数情况下,它们是一些`@Configuration`类的引用,但也可能是XML配置或要扫描包的引用。
-你也可以使用`application.properties`文件来配置`SpringApplication`,具体参考[24. Externalized 配置](24. Externalized Configuration.md),访问[SpringApplication Javadoc](https://docs.spring.io/spring-boot/docs/2.0.0.M5/api/org/springframework/boot/SpringApplication.html)可获取完整的配置选项列表.
+你也可以使用`application.properties`文件来配置`SpringApplication`,具体参考[24. Externalized 配置](24. Externalized Configuration.md),访问[SpringApplication Javadoc](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/SpringApplication.html)可获取完整的配置选项列表.
diff --git a/IV. Spring Boot features/23.4. Fluent Builder API.md b/IV. Spring Boot features/23.4. Fluent Builder API.md
new file mode 100644
index 00000000..0dc4f7ef
--- /dev/null
+++ b/IV. Spring Boot features/23.4. Fluent Builder API.md
@@ -0,0 +1,12 @@
+### 23.4. 流式构建API
+
+如果需要创建一个分层的`ApplicationContext`(多个具有父子关系的上下文),或喜欢使用流式(fluent)构建API,那你可以使用SpringApplicationBuilder。
+SpringApplicationBuilder让你以链式方式调用多个方法,包括parent和child方法,这样就可以创建多层次结构,例如:
+```java
+new SpringApplicationBuilder()
+ .sources(Parent.class)
+ .child(Application.class)
+ .bannerMode(Banner.Mode.OFF)
+ .run(args);
+```
+**注**:创建ApplicationContext层次时有些限制。比如,Web组件必须包含在子上下文中,并且父上下文和子上下文使用相同的Environment。具体参考[SpringApplicationBuilder javadoc](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/builder/SpringApplicationBuilder.html)。
diff --git a/IV. Spring Boot features/23.4. Fluent builder API.md b/IV. Spring Boot features/23.4. Fluent builder API.md
deleted file mode 100644
index 12127154..00000000
--- a/IV. Spring Boot features/23.4. Fluent builder API.md
+++ /dev/null
@@ -1,12 +0,0 @@
-### 23.4. 流式构建API
-
-如果需要创建一个分层的`ApplicationContext`(多个具有父子关系的上下文),或只是喜欢使用流式(fluent)构建API,那你可以使用SpringApplicationBuilder。
-SpringApplicationBuilder允许你以链式方式调用多个方法,包括parent和child方法,这样就可以创建多层次结构,例如:
-```java
-new SpringApplicationBuilder()
- .sources(Parent.class)
- .child(Application.class)
- .bannerMode(Banner.Mode.OFF)
- .run(args);
-```
-**注**:创建ApplicationContext层次时有些限制,比如,Web组件必须包含在子上下文中,并且父上下文和子上下文使用相同的Environment,具体参考[SpringApplicationBuilder javadoc](https://docs.spring.io/spring-boot/docs/2.0.0.M5/api/org/springframework/boot/builder/SpringApplicationBuilder.html)。
diff --git a/IV. Spring Boot features/23.5. Application Events and Listeners.md b/IV. Spring Boot features/23.5. Application Events and Listeners.md
new file mode 100644
index 00000000..093926b3
--- /dev/null
+++ b/IV. Spring Boot features/23.5. Application Events and Listeners.md
@@ -0,0 +1,23 @@
+### 23.5. 应用事件和监听器
+
+除了常见的Spring框架事件,比如[ContextRefreshedEvent](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/context/event/ContextRefreshedEvent.html),`SpringApplication`也会发送其他的应用事件。
+
+**注** 有些事件实际上是在`ApplicationContext`创建前触发的,所以你不能在那些事件(处理类)中通过`@Bean`注册监听器,只能通过`SpringApplication.addListeners(…)`或`SpringApplicationBuilder.listeners(…)`方法注册。如果想让监听器自动注册,而不关心应用的创建方式,你可以在工程中添加一个`META-INF/spring.factories`文件,并使用`org.springframework.context.ApplicationListener`作为key指向那些监听器,如下:
+```properties
+org.springframework.context.ApplicationListener=com.example.project.MyListener
+```
+
+应用运行时,事件会以下面的次序发送:
+
+1. 在运行开始,但除了监听器注册和初始化以外的任何处理之前,会发送一个`ApplicationStartingEvent`。
+2. 在Environment将被用于已知的上下文,但在上下文被创建前,会发送一个`ApplicationEnvironmentPreparedEvent`。
+3. 在refresh开始前,但在bean定义已被加载后,会发送一个`ApplicationPreparedEvent`。
+4. 在上下文更新后,但在任何应用和命令行运行器被调用前,会发送一个`ApplicationStartedEvent`。
+5. 在任何应用和命令行运行器被调用后,会发送一个`ApplicationReadyEvent`,表示应用准备好接收请求了。
+6. 启动过程中如果出现异常,会发送一个`ApplicationFailedEvent`。
+
+**注** 通常不需要使用应用事件,但知道它们的存在是有用的(在某些场合可能会使用到),比如,在Spring Boot内部会使用事件处理各种任务。
+
+应用事件通过Spring框架的事件发布机制发送。此机制的一部分确保了一个发布到子上下文里的监听器的事件,也会发布到任何祖先上下文里的监听器。因此,如果你的应用使用`SpringApplication`实例的层级,监听器可能会接收到应用事件的多个相同类型的实例。
+
+为了让你的监听器区分一个事件是对应它的上下文还是子孙上下文,它应当请求它的应用上下文被注入,然后比较注入的上下文与事件的上下文。上下文可以通过实现`ApplicationContextAware`注入。或者,如果监听器是一个bean,可以使用`@Autowired`。
diff --git a/IV. Spring Boot features/23.5. Application events and listeners.md b/IV. Spring Boot features/23.5. Application events and listeners.md
deleted file mode 100644
index 056a92e7..00000000
--- a/IV. Spring Boot features/23.5. Application events and listeners.md
+++ /dev/null
@@ -1,18 +0,0 @@
-### 23.5. Application事件和监听器
-
-除了常见的Spring框架事件,比如[ContextRefreshedEvent](https://docs.spring.io/spring/docs/5.0.0.RELEASE/javadoc-api/org/springframework/context/event/ContextRefreshedEvent.html),`SpringApplication`也会发送其他的application事件。
-
-**注** 有些事件实际上是在`ApplicationContext`创建前触发的,所以你不能在那些事件(处理类)中通过`@Bean`注册监听器,只能通过`SpringApplication.addListeners(…)`或`SpringApplicationBuilder.listeners(…)`方法注册。如果想让监听器自动注册,而不关心应用的创建方式,你可以在工程中添加一个`META-INF/spring.factories`文件,并使用`org.springframework.context.ApplicationListener`作为key指向那些监听器,如下:
-```properties
-org.springframework.context.ApplicationListener=com.example.project.MyListener
-```
-
-应用运行时,事件会以下面的次序发送:
-
-1. 在运行开始,但除了监听器注册和初始化以外的任何处理之前,会发送一个`ApplicationStartingEvent`。
-2. 在Environment将被用于已知的上下文,但在上下文被创建前,会发送一个`ApplicationEnvironmentPreparedEvent`。
-3. 在refresh开始前,但在bean定义已被加载后,会发送一个`ApplicationPreparedEvent`。
-4. 在refresh之后,相关的回调处理完,会发送一个`ApplicationReadyEvent`,表示应用准备好接收请求了。
-4. 启动过程中如果出现异常,会发送一个`ApplicationFailedEvent`。
-
-**注** 通常不需要使用application事件,但知道它们的存在是有用的(在某些场合可能会使用到),比如,在Spring Boot内部会使用事件处理各种任务。
diff --git a/IV. Spring Boot features/23.6. Web environment.md b/IV. Spring Boot features/23.6. Web Environment.md
similarity index 100%
rename from IV. Spring Boot features/23.6. Web environment.md
rename to IV. Spring Boot features/23.6. Web Environment.md
diff --git a/IV. Spring Boot features/23.7. Accessing application arguments.md b/IV. Spring Boot features/23.7. Accessing Application Arguments.md
similarity index 100%
rename from IV. Spring Boot features/23.7. Accessing application arguments.md
rename to IV. Spring Boot features/23.7. Accessing Application Arguments.md
diff --git a/IV. Spring Boot features/23.8. Using the ApplicationRunner or CommandLineRunner.md b/IV. Spring Boot features/23.8. Using the ApplicationRunner or CommandLineRunner.md
index 29531eed..67d86c21 100644
--- a/IV. Spring Boot features/23.8. Using the ApplicationRunner or CommandLineRunner.md
+++ b/IV. Spring Boot features/23.8. Using the ApplicationRunner or CommandLineRunner.md
@@ -2,7 +2,7 @@
如果需要在`SpringApplication`启动后执行一些特殊的代码,你可以实现`ApplicationRunner`或`CommandLineRunner`接口,这两个接口工作方式相同,都只提供单一的`run`方法,该方法仅在`SpringApplication.run(…)`完成之前调用。
-`CommandLineRunner`接口能够访问string数组类型的应用参数,而`ApplicationRunner`使用的是上面描述过的`ApplicationArguments`接口:
+`CommandLineRunner`接口能够访问string数组类型的应用参数,而`ApplicationRunner`使用的是之前描述过的`ApplicationArguments`接口:
```java
import org.springframework.boot.*
import org.springframework.stereotype.*
diff --git a/IV. Spring Boot features/23.9. Application Exit.md b/IV. Spring Boot features/23.9. Application Exit.md
new file mode 100644
index 00000000..309c8417
--- /dev/null
+++ b/IV. Spring Boot features/23.9. Application Exit.md
@@ -0,0 +1,22 @@
+### 23.9 应用退出
+
+为确保`ApplicationContext`在退出时被平静的(gracefully)关闭,每个`SpringApplication`都会注册一个JVM的shutdown钩子,所有标准的Spring生命周期回调(比如`DisposableBean`接口或`@PreDestroy`注解)都能使用。
+
+此外,如果想在`SpringApplication.exit()`被调用时返回特定的退出码(exit code),这些beans可以实现`org.springframework.boot.ExitCodeGenerator`接口。这个退出码之后会被传递到`System.exit()`,作为状态码返回。
+```java
+@SpringBootApplication
+public class ExitCodeApplication {
+
+ @Bean
+ public ExitCodeGenerator exitCodeGenerator() {
+ return () -> 42;
+ }
+
+ public static void main(String[] args) {
+ System.exit(SpringApplication
+ .exit(SpringApplication.run(ExitCodeApplication.class, args)));
+ }
+
+}
+```
+`ExitCodeGenerator`接口也可以被异常实现。当遇到这样的一个异常,Spring Boot将返回由被实现了的`getExitCode()`方法提供的退出码。
diff --git a/IV. Spring Boot features/23.9. Application exit.md b/IV. Spring Boot features/23.9. Application exit.md
deleted file mode 100644
index 55b14ea7..00000000
--- a/IV. Spring Boot features/23.9. Application exit.md
+++ /dev/null
@@ -1,22 +0,0 @@
-### 23.9 Application退出
-
-为确保`ApplicationContext`在退出时被平静的(gracefully)关闭,每个`SpringApplication`都会注册一个JVM的shutdown钩子,所有标准的Spring生命周期回调(比如`DisposableBean`接口或`@PreDestroy`注解)都能使用。
-
-此外,如果想在`SpringApplication.exit()`被调用时返回特定的退出码(exit code),这些beans可以实现`org.springframework.boot.ExitCodeGenerator`接口。这个退出码之后会被传递到`System.exit()`,作为状态码返回。
-```java
-@SpringBootApplication
-public class ExitCodeApplication {
-
- @Bean
- public ExitCodeGenerator exitCodeGenerator() {
- return () -> 42;
- }
-
- public static void main(String[] args) {
- System.exit(SpringApplication
- .exit(SpringApplication.run(ExitCodeApplication.class, args)));
- }
-
-}
-```
-`ExitCodeGenerator`接口也可以被异常实现。当遇到这样的一个异常,Spring Boot将返回由被实现了的`getExitCode()`方法提供的退出码。
\ No newline at end of file
diff --git a/IV. Spring Boot features/24. Externalized Configuration.md b/IV. Spring Boot features/24. Externalized Configuration.md
index 73bfe7d3..e612de08 100644
--- a/IV. Spring Boot features/24. Externalized Configuration.md
+++ b/IV. Spring Boot features/24. Externalized Configuration.md
@@ -1,12 +1,12 @@
### 24.外部化配置
-Spring Boot允许将配置外部化(externalize),这样你就能够在不同的环境下使用相同的代码。你可以使用properties文件,YAML文件,环境变量和命令行参数来外部化配置。使用@Value注解,可以直接将属性值注入到beans中,然后通过Spring的`Environment`抽象或通过`@ConfigurationProperties`[绑定到结构化对象](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties)来访问。
+Spring Boot允许将配置外部化(externalize),这样你就能够在不同的环境下使用相同的代码。你可以使用properties文件,YAML文件,环境变量和命令行参数来外部化配置。使用@Value注解,可以直接将属性值注入到beans中,然后通过Spring的`Environment`抽象或通过`@ConfigurationProperties`[绑定到结构化对象](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties)来访问。
Spring Boot设计了一个非常特别的`PropertySource`顺序,以允许对属性值进行合理的覆盖,属性会以如下的顺序进行设值:
-1. home目录下的[devtools全局设置属性](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#using-boot-devtools-globalsettings)(`~/.spring-boot-devtools.properties`,如果devtools激活)。
-2. 测试用例上的[@TestPropertySource](https://docs.spring.io/spring/docs/5.0.0.RELEASE/javadoc-api/org/springframework/test/context/TestPropertySource.html)注解。
-3. 测试用例上的[@SpringBootTest#properties](http://docs.spring.io/spring-boot/docs/2.0.0.M5/api/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.html)注解。
+1. home目录下的[devtools全局设置属性](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#using-boot-devtools-globalsettings)(`~/.spring-boot-devtools.properties`,如果devtools激活)。
+2. 测试用例上的[@TestPropertySource](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/test/context/TestPropertySource.html)注解。
+3. 测试用例上的[@SpringBootTest#properties](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.html)注解。
4. 命令行参数
5. 来自`SPRING_APPLICATION_JSON`的属性(环境变量或系统属性中内嵌的内联JSON)。
6. `ServletConfig`初始化参数。
@@ -15,12 +15,12 @@ Spring Boot设计了一个非常特别的`PropertySource`顺序,以允许对
9. Java系统属性(System.getProperties())。
10. 操作系统环境变量。
11. RandomValuePropertySource,只包含`random.*`中的属性。
-12. 没有打进jar包的[Profile-specific应用属性](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML变量)。
-13. 打进jar包中的[Profile-specific应用属性](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML变量)。
+12. 没有打进jar包的[Profile-specific应用属性](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML变量)。
+13. 打进jar包中的[Profile-specific应用属性](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML变量)。
14. 没有打进jar包的应用配置(`application.properties`和YAML变量)。
15. 打进jar包中的应用配置(`application.properties`和YAML变量)。
-16. `@Configuration`类上的[`@PropertySource`注解](https://docs.spring.io/spring/docs/5.0.0.RELEASE/javadoc-api/org/springframework/context/annotation/PropertySource.html)。
-17. 默认属性(使用`SpringApplication.setDefaultProperties`指定)。
+16. `@Configuration`类上的[`@PropertySource`注解](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/context/annotation/PropertySource.html)。
+17. 默认属性(通过设置`SpringApplication.setDefaultProperties`指定)。
下面是具体的示例,假设你开发一个使用name属性的`@Component`:
```java
@@ -38,14 +38,14 @@ public class MyBean {
**注** `SPRING_APPLICATION_JSON`属性可以通过命令行的环境变量设置,例如,在一个UNIX shell中可以这样:
```shell
-$ SPRING_APPLICATION_JSON='{"foo":{"bar":"spam"}}' java -jar myapp.jar
+$ SPRING_APPLICATION_JSON='{"acme":{"name":"test"}}' java -jar myapp.jar
```
-本示例中,如果是Spring `Environment`,你可以以`foo.bar=spam`结尾;如果在一个系统变量中,可以提供作为`spring.application.json`的JSON字符串:
+在之前的例子里,如果是Spring `Environment`,你可以以`acme.name=test`结尾;如果在一个系统属性中,可以提供作为`spring.application.json`的JSON字符串:
```shell
-$ java -Dspring.application.json='{"foo":"bar"}' -jar myapp.jar
+$ java -Dspring.application.json='{"name":"test"}' -jar myapp.jar
```
或命令行参数:
```shell
-$ java -jar myapp.jar --spring.application.json='{"foo":"bar"}'
+$ java -jar myapp.jar --spring.application.json='{"name":"test"}'
```
或作为一个JNDI变量`java:comp/env/spring.application.json`。
diff --git a/IV. Spring Boot features/24.1. Configuring random values.md b/IV. Spring Boot features/24.1. Configuring Random Values.md
similarity index 100%
rename from IV. Spring Boot features/24.1. Configuring random values.md
rename to IV. Spring Boot features/24.1. Configuring Random Values.md
diff --git a/IV. Spring Boot features/24.2. Accessing Command Line Properties.md b/IV. Spring Boot features/24.2. Accessing Command Line Properties.md
new file mode 100644
index 00000000..3412354a
--- /dev/null
+++ b/IV. Spring Boot features/24.2. Accessing Command Line Properties.md
@@ -0,0 +1,5 @@
+### 24.2. 访问命令行属性
+
+默认情况下,`SpringApplication`会将所有命令行配置参数(以--开头,比如`--server.port=9000`)转化成一个`property`,并将其添加到Spring `Environment`中。正如以上章节提过的,命令行属性总是优先于其他属性源。
+
+如果不想将命令行属性添加到`Environment`,你可以使用`SpringApplication.setAddCommandLineProperties(false)`来禁用它们。
diff --git a/IV. Spring Boot features/24.2. Accessing command line properties.md b/IV. Spring Boot features/24.2. Accessing command line properties.md
deleted file mode 100644
index 3f2354bc..00000000
--- a/IV. Spring Boot features/24.2. Accessing command line properties.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 24.2. 访问命令行属性
-
-默认情况下,`SpringApplication`会将所有命令行配置参数(以'--'开头,比如`--server.port=9000`)转化成一个`property`,并将其添加到Spring `Environment`中。正如以上章节提过的,命令行属性总是优先于其他属性源。
-
-如果不想将命令行属性添加到`Environment`,你可以使用`SpringApplication.setAddCommandLineProperties(false)`来禁用它们。
diff --git a/IV. Spring Boot features/24.3. Application Property Files.md b/IV. Spring Boot features/24.3. Application Property Files.md
new file mode 100644
index 00000000..d182ab84
--- /dev/null
+++ b/IV. Spring Boot features/24.3. Application Property Files.md
@@ -0,0 +1,51 @@
+### 24.3. 应用属性文件
+
+`SpringApplication`从以下位置加载`application.properties`文件,并把它们添加到Spring `Environment`中:
+
+1. 当前目录下的`/config`子目录
+2. 当前目录
+3. classpath下的`/config`包
+4. classpath根路径(root)
+
+该列表是按优先级排序的(列表中位置高的路径下定义的属性将覆盖位置低的)。
+
+**注** 你可以使用[YAML('.yml')文件](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-yaml)替代'.properties'。
+
+如果不喜欢将`application.properties`作为配置文件名,你可以通过指定`spring.config.name`环境属性来切换其它的文件名,也可以使用`spring.config.location`环境属性引用一个明确的路径(目录位置或文件路径列表以逗号分割)。下面的例子展示了怎么指定一个不同的文件名:
+```shell
+$ java -jar myproject.jar --spring.config.name=myproject
+```
+下面的例子展示了怎么指定两个路径:
+```shell
+$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
+```
+**注** 在初期需要根据`spring.config.name`和`spring.config.location`决定加载哪个文件,所以它们必须定义为环境属性(通常为OS环境变量,系统属性或命令行参数)。
+
+如果`spring.config.location`包含目录(相对于文件),那它们应该以`/`结尾(运行时,`spring.config.name`关联的名称会在被加载前被追加到后面,包括profile-specific的文件名)。`spring.config.location`下定义的文件使用方法跟往常一样,没有profile-specific变量支持的属性,会被profile-specific的属性覆盖。
+
+配置位置按相反的顺序搜索。默认地,配置好的位置是`classpath:/,classpath:/config/,file:./,file:./config/`。产生的搜索顺序为:
+
+1. `file:./config/`
+2. `file:./`
+3. `classpath:/config/`
+4. `classpath:/`
+
+当使用`spring.config.location`配置好自定义的配置位置时,它们会代替默认位置。比如,如果用值`classpath:/custom-config/,file:./custom-config/`配置了`spring.config.location`,搜索顺序会变成:
+
+1. `file:./custom-config/`
+2. `classpath:custom-config/`
+
+或者,当使用`spring.config.additional-location`配置好自定义的配置位置时,,它们会在默认位置的基础上被使用。自定义的位置会在默认位置之前被搜索。例如,如果配置了自定义的位置`classpath:/custom-config/,file:./custom-config/`,搜索的顺序会变成:
+
+1. `file:./custom-config/`
+2. `classpath:custom-config/`
+3. `file:./config/`
+4. `file:./`
+5. `classpath:/config/`
+6. `classpath:/`
+
+这种搜索排序允许你在一个配置文件里指定默认值,然后有选择地覆盖那些值。你可以选择默认位置中的一处,在这儿的`application.properties`(或者任何由`spring.config.name`指定的名字)里为应用设置默认值。然后,在运行时使用在自定义的位置上的不同的文件,覆盖这些默认值。
+
+**注** 如果使用环境变量而不是系统属性,需要注意多数操作系统的key名称不允许以句号分割(period-separated),但你可以使用下划线(underscores)代替(比如,使用`SPRING_CONFIG_NAME`代替`spring.config.name`)。
+
+**注** 如果你的应用运行在容器中,那么JNDI属性(java:comp/env)或servlet上下文初始化参数可以用来代替环境变量或系统属性,当然也可以使用环境变量或系统属性。
diff --git a/IV. Spring Boot features/24.3. Application property files.md b/IV. Spring Boot features/24.3. Application property files.md
deleted file mode 100644
index 30906df0..00000000
--- a/IV. Spring Boot features/24.3. Application property files.md
+++ /dev/null
@@ -1,46 +0,0 @@
-### 24.3. Application属性文件
-
-`SpringApplication`将从以下位置加载`application.properties`文件,并把它们添加到Spring `Environment`中:
-
-1. 当前目录下的`/config`子目录。
-2. 当前目录。
-3. classpath下的`/config`包。
-4. classpath根路径(root)。
-
-该列表是按优先级排序的(列表中位置高的路径下定义的属性将覆盖位置低的)。
-
-**注** 你可以使用[YAML('.yml')文件](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-yaml)替代'.properties'。
-
-如果不喜欢将`application.properties`作为配置文件名,你可以通过指定`spring.config.name`环境属性来切换其他的名称,也可以使用`spring.config.location`环境属性引用一个明确的路径(目录位置或文件路径列表以逗号分割)。
-```shell
-$ java -jar myproject.jar --spring.config.name=myproject
-```
-或
-```shell
-$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
-```
-**注** 在初期需要根据`spring.config.name`和`spring.config.location`决定加载哪个文件,所以它们必须定义为environment属性(通常为OS env,系统属性或命令行参数)。
-
-如果`spring.config.location`包含目录(相对于文件),那它们应该以`/`结尾(在被加载前,`spring.config.name`关联的名称将被追加到后面,包括profile-specific的文件名)。`spring.config.location`下定义的文件使用方法跟往常一样,没有profile-specific变量支持的属性,将被profile-specific的属性覆盖。
-
-配置位置按相反的顺序搜索。默认地,配置好的位置是`classpath:/,classpath:/config/,file:./,file:./config/`。产生的搜索顺序为:
-
-1.`file:./config/`
-2.`file:./`
-3.`classpath:/config/`
-4.`classpath:/`
-
-当自定义的配置位置配置好时,它们会在默认位置的基础上被使用。自定义的位置会在默认位置之前被搜索。例如,如果配置了自定义的位置`classpath:/custom-config/,file:./custom-config/`,搜索的顺序会变成:
-
-1.`file:./custom-config/`
-2.`classpath:custom-config/`
-3.`file:./config/`
-4.`file:./`
-5.`classpath:/config/`
-6.`classpath:/`
-
-这种搜索排序允许你在一个配置文件里指定默认值,然后有选择地覆盖那些值。你可以选择默认位置中的一处,在这儿的`application.properties`(或者任何由`spring.config.name`指定的名字)里为应用设置默认值。然后,在运行时使用在自定义的位置上的不同的文件,覆盖这些默认值。
-
-**注** 如果使用环境变量而不是系统属性,需要注意多数操作系统的key名称不允许以句号分割(period-separated),但你可以使用下划线(underscores)代替(比如,使用`SPRING_CONFIG_NAME`代替`spring.config.name`)。
-
-**注** 如果应用运行在容器中,那么JNDI属性(java:comp/env)或servlet上下文初始化参数可以用来代替环境变量或系统属性,当然也可以使用环境变量或系统属性。
diff --git a/IV. Spring Boot features/24.4. Profile-specific Properties.md b/IV. Spring Boot features/24.4. Profile-specific Properties.md
new file mode 100644
index 00000000..1618d4bb
--- /dev/null
+++ b/IV. Spring Boot features/24.4. Profile-specific Properties.md
@@ -0,0 +1,9 @@
+### 24.4. Profile-specific属性
+
+除了`application.properties`文件,profile-specific属性也能通过命名惯例`application-{profile}.properties`定义。`Environment`(Spring的环境抽象接口)有个默认profiles集合(默认情况为`[default]`),在没有设置激活的profiles时会被使用。换句话说,如果没有明确指定激活的profiles,`application-default.properties`中的属性会被加载。
+
+Profile-specific属性加载路径和标准的`application.properties`相同,并且profile-specific文件总是会覆盖non-specific文件,不管profile-specific文件是否被打包到jar中。
+
+如果定义多个profiles,最后一个将获胜。例如,`spring.profiles.active`定义的profiles被添加到通过`SpringApplication`API定义的profiles后面,因此优先级更高。
+
+**注** 如果你已经在`spring.config.location`下定义所有文件(非目录),那些profile-specific的文件将不被考虑。如果想使用profile-specific属性,那就在`spring.config.location`下使用目录。
diff --git a/IV. Spring Boot features/24.4. Profile-specific properties.md b/IV. Spring Boot features/24.4. Profile-specific properties.md
deleted file mode 100644
index 908fc5c6..00000000
--- a/IV. Spring Boot features/24.4. Profile-specific properties.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 24.4. Profile-specific属性
-
-除了`application.properties`文件,profile-specific属性也能通过命名惯例`application-{profile}.properties`定义。`Environment`(Spring的环境抽象接口)有个默认profiles集合(默认情况为`[default]`),在没有设置激活的profiles时会被使用(例如,如果没有明确指定激活的profiles,`application-default.properties`中的属性会被加载)。
-
-Profile-specific属性加载路径和标准的`application.properties`相同,并且profile-specific文件总是会覆盖non-specific文件,不管profile-specific文件是否被打包到jar中。
-
-如果定义多个profiles,最后一个将获胜。例如,`spring.profiles.active`定义的profiles被添加到通过`SpringApplication`API定义的profiles后面,因此优先级更高。
-
-**注** 如果你已经在`spring.config.location`下定义所有文件(非目录),那些profile-specific的文件将不被考虑。如果想使用profile-specific属性,那就在`spring.config.location`下使用目录。
-
-
diff --git a/IV. Spring Boot features/24.5. Placeholders in Properties.md b/IV. Spring Boot features/24.5. Placeholders in Properties.md
new file mode 100644
index 00000000..f15ead3d
--- /dev/null
+++ b/IV. Spring Boot features/24.5. Placeholders in Properties.md
@@ -0,0 +1,8 @@
+### 24.5. 属性占位符
+
+当使用`application.properties`定义的属性时,Spring会先通过已经存在的`Environment`查找该属性,所以你可以引用事先定义的值(比如,系统属性):
+```java
+app.name=MyApp
+app.description=${app.name} is a Spring Boot application
+```
+**注** 你也可以使用该技巧为存在的Spring Boot属性创建'短'变量,具体参考[章节 74.4,使用'short'命令行参数](../IX. ‘How-to’ guides/74.4 Use ‘Short’ Command Line Arguments.md)。
diff --git a/IV. Spring Boot features/24.5. Placeholders in properties.md b/IV. Spring Boot features/24.5. Placeholders in properties.md
deleted file mode 100644
index 02aeb779..00000000
--- a/IV. Spring Boot features/24.5. Placeholders in properties.md
+++ /dev/null
@@ -1,8 +0,0 @@
-### 24.5. 属性占位符
-
-当使用`application.properties`定义的属性时,Spring会先通过已经存在的`Environment`查找该属性,所以你可以引用事先定义的值(比如,系统属性):
-```java
-app.name=MyApp
-app.description=${app.name} is a Spring Boot application
-```
-**注** 你也可以使用该技巧为存在的Spring Boot属性创建'短'变量,具体参考[章节 73.4,使用'short'命令行参数](../IX. ‘How-to’ guides/73.4 Use ‘short’ command line arguments.md)。
diff --git a/IV. Spring Boot features/24.6. Using YAML Instead of Properties.md b/IV. Spring Boot features/24.6. Using YAML Instead of Properties.md
new file mode 100644
index 00000000..582b53bd
--- /dev/null
+++ b/IV. Spring Boot features/24.6. Using YAML Instead of Properties.md
@@ -0,0 +1,5 @@
+### 24.6. 使用YAML代替Properties
+
+[YAML](http://yaml.org/)是JSON的一个超集,也是一种方便的定义层次配置数据的格式。只要你将[SnakeYAML ](http://code.google.com/p/snakeyaml/)库放到classpath下,`SpringApplication`就会自动支持YAML,以作为properties的替换。
+
+**注** 如果你使用“Starters”,添加`spring-boot-starter`依赖会自动加载SnakeYAML。
diff --git a/IV. Spring Boot features/24.6. Using YAML instead of Properties.md b/IV. Spring Boot features/24.6. Using YAML instead of Properties.md
deleted file mode 100644
index 8e648269..00000000
--- a/IV. Spring Boot features/24.6. Using YAML instead of Properties.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 24.6. 使用YAML代替Properties
-
-[YAML](http://yaml.org/)是JSON的一个超集,也是一种方便的定义层次配置数据的格式。只要你将[SnakeYAML ](http://code.google.com/p/snakeyaml/)库放到classpath下,`SpringApplication`就会自动支持YAML,以作为properties的替换。
-
-**注** 如果你使用'Starters',添加`spring-boot-starter`依赖会自动加载SnakeYAML。
diff --git a/IV. Spring Boot features/24.6.1. Loading YAML.md b/IV. Spring Boot features/24.6.1. Loading YAML.md
index 9fefdfbc..9ea301c3 100644
--- a/IV. Spring Boot features/24.6.1. Loading YAML.md
+++ b/IV. Spring Boot features/24.6.1. Loading YAML.md
@@ -6,32 +6,32 @@ Spring框架提供两个便利的类用于加载YAML文档,`YamlPropertiesFact
```json
environments:
dev:
- url: http://dev.bar.com
+ url: http://dev.example.com
name: Developer Setup
prod:
- url: http://foo.bar.com
+ url: http://another.example.com
name: My Cool App
```
-会被转化到这些属性:
+会被转化为如下属性:
```java
-environments.dev.url=http://dev.bar.com
+environments.dev.url=http://dev.example.com
environments.dev.name=Developer Setup
-environments.prod.url=http://foo.bar.com
+environments.prod.url=http://another.example.com
environments.prod.name=My Cool App
```
YAML列表被表示成使用`[index]`间接引用作为属性keys的形式,例如下面的YAML:
```json
my:
servers:
- - dev.bar.com
- - foo.bar.com
+ - dev.example.com
+ - another.example.com
```
将会转化到这些属性:
```java
-my.servers[0]=dev.bar.com
-my.servers[1]=foo.bar.com
+my.servers[0]=dev.example.com
+my.servers[1]=another.example.com
```
-使用Spring `DataBinder`工具集绑定这些属性(这是`@ConfigurationProperties`做的事)时,你需要确保目标bean有个`java.util.List`或`Set`类型的属性,并且需要提供一个setter或使用可变的值初始化它,比如,下面的代码将绑定上面的属性:
+使用Spring `DataBinder`工具集绑定这些属性(这是`@ConfigurationProperties`做的事)时,你需要确保目标bean有个`java.util.List`或`Set`类型的属性,并且需要提供一个setter或使用可变的值初始化它,比如,下面的代码将绑定之前的属性:
```java
@ConfigurationProperties(prefix="my")
public class Config {
@@ -42,8 +42,4 @@ public class Config {
}
```
-**注** 当配置列表时需要格外小心,因为重写并不会像你期望的那样发生。在上面的例子中,当my.servers在几个地方被重新定义时,个别的元素会被重写,而不是列表。 为了确保拥有更高优先权的属性源能够重写列表,你需要把它定义为单个的属性:
-```java
- my :
- servers : dev.bar.com,foo.bar.com
-```
+**注** 当多个位置配置了列表,重写通过替换整个列表发生。在之前的例子里,当在几个地方定义了`my.servers`,来自`PropertySource`拥有更高优先级的整个列表会重写那个列表的任何其它的配置。可以使用逗号分隔的列表和YAML列表来完全重写列表的内容。
diff --git a/IV. Spring Boot features/24.6.2. Exposing YAML as Properties in the Spring Environment.md b/IV. Spring Boot features/24.6.2. Exposing YAML as Properties in the Spring Environment.md
new file mode 100644
index 00000000..19196af0
--- /dev/null
+++ b/IV. Spring Boot features/24.6.2. Exposing YAML as Properties in the Spring Environment.md
@@ -0,0 +1,3 @@
+### 24.6.2. 在Spring环境中使用YAML暴露属性
+
+`YamlPropertySourceLoader`类能够将YAML作为`PropertySource`导出到Sprig `Environment`,这允许你使用`@Value`注解配合占位符语法访问YAML属性。
diff --git a/IV. Spring Boot features/24.6.2. Exposing YAML as properties in the Spring Environment.md b/IV. Spring Boot features/24.6.2. Exposing YAML as properties in the Spring Environment.md
deleted file mode 100644
index 707a396d..00000000
--- a/IV. Spring Boot features/24.6.2. Exposing YAML as properties in the Spring Environment.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 24.6.2. 在Spring环境中使用YAML暴露属性
-
-`YamlPropertySourceLoader`类能够将YAML作为`PropertySource`导出到Sprig `Environment`,这允许你使用常用的`@Value`注解配合占位符语法访问YAML属性。
diff --git a/IV. Spring Boot features/24.6.3. Multi-profile YAML Documents.md b/IV. Spring Boot features/24.6.3. Multi-profile YAML Documents.md
new file mode 100644
index 00000000..29bfda51
--- /dev/null
+++ b/IV. Spring Boot features/24.6.3. Multi-profile YAML Documents.md
@@ -0,0 +1,40 @@
+### 24.6.3. Multi-profile YAML文档
+
+你可以在单个文件中定义多个特定配置(profile-specific)的YAML文档,并通过`spring.profiles`标示生效的文档,例如:
+```json
+server:
+ address: 192.168.1.100
+---
+spring:
+ profiles: development
+server:
+ address: 127.0.0.1
+---
+spring:
+ profiles: production
+server:
+ address: 192.168.1.120
+```
+在之前的例子中,如果`development` profile被激活,`server.address`属性将是`127.0.0.1`。相似的,如果`production` profile被激活,`server.address`属性将是`192.168.1.120`。如果`development`和`production` profiles没有启用,则该属性的值将是`192.168.1.100`。
+
+在应用上下文启动时,如果没有明确指定激活的profiles,则默认的profiles将生效。所以,在下面的文档中我们为`spring.security.user.password`设置了一个值,该值只在"default" profile中有效:
+```properties
+server:
+ port: 8000
+---
+spring:
+ profiles: default
+security:
+ user:
+ password: weak
+```
+然而,在这个示例中,由于没有关联任何profile,密码总是会设置,并且如果有必要的话可以在其他profiles中显式重置:
+```properties
+server:
+ port: 8000
+spring:
+ security:
+ user:
+ password: weak
+```
+通过`!`可以对`spring.profiles`指定的profiles进行取反(negated,跟java中的`!`作用一样),如果negated和non-negated profiles都指定一个单一文件,至少需要匹配一个non-negated profile,可能不会匹配任何negated profiles。
diff --git a/IV. Spring Boot features/24.6.3. Multi-profile YAML documents.md b/IV. Spring Boot features/24.6.3. Multi-profile YAML documents.md
deleted file mode 100644
index 570e7001..00000000
--- a/IV. Spring Boot features/24.6.3. Multi-profile YAML documents.md
+++ /dev/null
@@ -1,39 +0,0 @@
-### 24.6.3. Multi-profile YAML文档
-
-你可以在单个文件中定义多个特定配置(profile-specific)的YAML文档,并通过`spring.profiles`标示生效的文档,例如:
-```json
-server:
- address: 192.168.1.100
----
-spring:
- profiles: development
-server:
- address: 127.0.0.1
----
-spring:
- profiles: production
-server:
- address: 192.168.1.120
-```
-在以上例子中,如果`development` profile被激活,`server.address`属性将是`127.0.0.1`;如果`development`和`production` profiles没有启用,则该属性的值将是`192.168.1.100`。
-
-在应用上下文启动时,如果没有明确指定激活的profiles,则默认的profiles将生效。所以,在下面的文档中我们为`security.user.password`设置了一个值,该值只在"default" profile中有效:
-```properties
-server:
- port: 8000
----
-spring:
- profiles: default
-security:
- user:
- password: weak
-```
-然而,在这个示例中,由于没有关联任何profile,密码总是会设置,并且如果有必要的话可以在其他profiles中显式重置:
-```properties
-server:
- port: 8000
-security:
- user:
- password: weak
-```
-通过`!`可以对`spring.profiles`指定的profiles进行取反(negated,跟java中的`!`作用一样),如果negated和non-negated profiles都指定一个单一文件,至少需要匹配一个non-negated profile,可能不会匹配任何negated profiles。
diff --git a/IV. Spring Boot features/24.6.4. YAML shortcomings.md b/IV. Spring Boot features/24.6.4. YAML Shortcomings.md
similarity index 100%
rename from IV. Spring Boot features/24.6.4. YAML shortcomings.md
rename to IV. Spring Boot features/24.6.4. YAML Shortcomings.md
diff --git a/IV. Spring Boot features/24.6.5. Merging YAML Lists.md b/IV. Spring Boot features/24.6.5. Merging YAML Lists.md
new file mode 100644
index 00000000..63dabeb6
--- /dev/null
+++ b/IV. Spring Boot features/24.6.5. Merging YAML Lists.md
@@ -0,0 +1,46 @@
+### 24.6.5 合并YAML列表
+
+正如[之前](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-loading-yaml)展示的,所有YAML最终都转换为properties,在通过一个profile覆盖"list"属性时这个过程可能不够直观(counter intuitive)。例如,假设有一个`MyPojo`对象,默认它的`name`和`description`属性都为`null`。下面的例子从`AcmeProperties`暴露一个`MyPojo`对象列表(list):
+```java
+@ConfigurationProperties("acme")
+public class AcmeProperties {
+
+ private final List list = new ArrayList<>();
+
+ public List getList() {
+ return this.list;
+ }
+
+}
+```
+考虑如下配置:
+```properties
+acme:
+ list:
+ - name: my name
+ description: my description
+---
+spring:
+ profiles: dev
+acme:
+ list:
+ - name: my another name
+```
+如果`dev` profile没有激活,`AcmeProperties.list`将包括一个如之前定义的`MyPojo`实体。即使`dev`生效,该`list`仍旧只包含一个实体(`name`值为`my another name`,`description`值为`null`)。此配置不会向该列表添加第二个`MyPojo`实例,也不会对该项进行合并。
+
+当一个集合定义在多个profiles时,只使用优先级最高的。考虑下面的例子:
+```properties
+acme:
+ list:
+ - name: my name
+ description: my description
+ - name: another name
+ description: another description
+---
+spring:
+ profiles: dev
+acme:
+ list:
+ - name: my another name
+```
+在之前的示例中,如果`dev` profile激活,`AcmeProperties.list`将包含一个`MyPojo`实体(`name`值为`my another name`,`description`值为`null`)。
diff --git a/IV. Spring Boot features/24.6.5. Merging YAML lists.md b/IV. Spring Boot features/24.6.5. Merging YAML lists.md
deleted file mode 100644
index 1cd200b4..00000000
--- a/IV. Spring Boot features/24.6.5. Merging YAML lists.md
+++ /dev/null
@@ -1,46 +0,0 @@
-###24.6.5 合并YAML列表
-
-正如[上面](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-loading-yaml)看到的,所有YAML最终都转换为properties,在通过一个profile覆盖"list"属性时这个过程可能不够直观(counter intuitive)。例如,假设有一个`MyPojo`对象,默认它的`name`和`description`属性都为`null`,下面我们将从`FooProperties`暴露一个`MyPojo`对象列表(list):
-```java
-@ConfigurationProperties("foo")
-public class FooProperties {
-
- private final List list = new ArrayList<>();
-
- public List getList() {
- return this.list;
- }
-
-}
-```
-考虑如下配置:
-```properties
-foo:
- list:
- - name: my name
- description: my description
----
-spring:
- profiles: dev
-foo:
- list:
- - name: my another name
-```
-如果`dev` profile没有激活,`FooProperties.list`将包括一个如上述定义的`MyPojo`实体,即使`dev`生效,该`list`仍旧只包含一个实体(`name`值为`my another name`,`description`值为`null`)。此配置不会向该列表添加第二个`MyPojo`实例,也不会对该项进行合并。
-
-当一个集合定义在多个profiles时,只使用优先级最高的:
-```properties
-foo:
- list:
- - name: my name
- description: my description
- - name: another name
- description: another description
----
-spring:
- profiles: dev
-foo:
- list:
- - name: my another name
-```
-在以上示例中,如果`dev` profile激活,`FooProperties.list`将包含一个`MyPojo`实体(`name`值为`my another name`,`description`值为`null`)。
diff --git a/IV. Spring Boot features/24.7. Type-safe Configuration Properties.md b/IV. Spring Boot features/24.7. Type-safe Configuration Properties.md
index 76679e17..86feb628 100644
--- a/IV. Spring Boot features/24.7. Type-safe Configuration Properties.md
+++ b/IV. Spring Boot features/24.7. Type-safe Configuration Properties.md
@@ -1,6 +1,6 @@
### 24.7. 类型安全的配置属性
-使用`@Value("${property}")`注解注入配置属性有时会比较麻烦(cumbersome),特别是需要使用多个properties,或数据本身有层次结构。Spring Boot提供一种使用配置的替代方法,这种方法允许强类型的beans以管理和校验应用的配置。
+使用`@Value("${property}")`注解注入配置属性有时会比较难处理,特别是但你需要使用多个properties,或者数据本身有层次结构的时候。Spring Boot提供一种可选的使用配置的方法,这种方法让强类型的beans来管理和校验应用的配置,如下所示:
```java
package com.example;
@@ -11,8 +11,8 @@ import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
-@ConfigurationProperties("foo")
-public class FooProperties {
+@ConfigurationProperties("acme")
+public class AcmeProperties {
private boolean enabled;
@@ -53,46 +53,46 @@ public class FooProperties {
}
}
```
-上面的POJO定义了如下的属性:
+之前的POJO定义了如下的属性:
-- foo.enabled,默认为false
+- acme.enabled,默认值为false
-- foo.remote-address,带有一个能从String转换的类型
+- acme.remote-address,带有一个能从String转换的类型
-- foo.security.username,有一个嵌套的“security”,它的名字由属性名定义。特别的,返回类型没有在那儿被使用,本来可以是SecurityProperties。
+- acme.security.username,有一个嵌套的“security”对象,它的名字由属性名定义。特别的,返回类型没有在那儿被使用,本来可以是SecurityProperties。
-- foo.security.password
+- acme.security.password
-- foo.security.roles,一个String的集合
+- acme.security.roles,一个String的集合
**注意** getters和setters时常是必须的。因为跟Spring MVC一样,绑定是通过标准的Java Beans属性描述符进行的。但是也有不需要setter的情况:
- Maps,只要它们被初始化了,需要getter,但setter不是必须的。因为binder能够改变它们。
-- Collections和arrays能够通过索引(通常用YAML),或者使用单个的由逗号分隔的值(属性)存取。 在后面的情况下,setter是必须的。对于这些类型,我们建议总是加上setter。如果你初始化一个collection,确保它不是不可变的(如同上面的例子)。
+- Collections和arrays能够通过索引(通常用YAML),或者使用单个的由逗号分隔的值(属性)存取。 在后面的情况下,setter是必须的。对于这些类型,我们建议总是加上setter。如果你初始化一个collection,确保它不是不可变的(如同之前的例子)。
-- 如果嵌套的POJO属性被初始化(就像上面例子里的Security域),setter就不需要。如果你想要binder使用它默认的构造器,即时创建一个实例,你就需要一个setter。
+- 如果嵌套的POJO属性被初始化(就像之前例子里的Security域),setter就不需要。如果你想要binder使用它默认的构造器,即时创建一个实例,你就需要一个setter。
有些人使用Project Lombok自动添加getters和setters。确保Lombok不会为这些类型生成任何特别的构造器,因为它会自动地被容器使用,来实例化对象。
-**提示** 查看[@Value和@ConfigurationProperties](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-vs-value)之间的区别。
+**提示** 查看[@Value和@ConfigurationProperties](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-vs-value)之间的区别。
-你需要在`@EnableConfigurationProperties`注解中列出要注册的属性类:
+你需要在`@EnableConfigurationProperties`注解中列出要注册的属性类,如下所示:
```java
@Configuration
-@EnableConfigurationProperties(FooProperties.class)
+@EnableConfigurationProperties(AcmeProperties.class)
public class MyConfiguration {
}
```
-**注** 当`@ConfigurationProperties` bean以这种方式注册时,该bean将有个约定的名称:`-`,``是`@ConfigurationProperties`注解中定义的environment key前缀,``是bean的全限定名。如果注解中没有提供任何前缀,那就只使用bean的全限定名。上述示例中的bean名称将是`foo-com.example.FooProperties`。
+**注** 当`@ConfigurationProperties` bean以这种方式注册时,该bean将有个约定的名称:`-`,``是`@ConfigurationProperties`注解中定义的environment key前缀,``是bean的全限定名。如果注解中没有提供任何前缀,那就只使用bean的全限定名。上述示例中的bean名称将是`acme-com.example.AcmeProperties`。
-尽管上述配置为`FooProperties`创建了一个常规的bean,不过我们建议`@ConfigurationProperties`只用来处理environment(只用于注入配置,系统环境之类的),特别是不要注入上下文中的其他beans。话虽如此,`@EnableConfigurationProperties`注解会自动应用到你的项目,任何存在的,注解`@ConfigurationProperties`的bean将会从`Environment`中得到配置。只要确定`FooProperties`是一个已存在的bean,`MyConfiguration`就可以不用了。
+尽管上述配置为`FooProperties`创建了一个常规的bean,不过我们建议`@ConfigurationProperties`只用来处理environment(只用于注入配置,系统环境之类的),特别是不要注入上下文中的其他beans。话虽如此,`@EnableConfigurationProperties`注解会自动应用到你的项目,任何存在的,注解`@ConfigurationProperties`的bean将会从`Environment`中得到配置。只要确定`AcmeProperties`是一个已存在的bean,`MyConfiguration`就可以不用了。
```java
@Component
-@ConfigurationProperties(prefix="foo")
-public class FooProperties {
+@ConfigurationProperties(prefix="acme")
+public class AcmeProperties {
- // ... see above
+ // ... see the preceding example
}
```
@@ -100,10 +100,10 @@ public class FooProperties {
```json
# application.yml
-foo:
+acme:
remote-address: 192.168.1.1
security:
- username: foo
+ username: admin
roles:
- USER
- ADMIN
@@ -115,10 +115,10 @@ foo:
@Service
public class MyService {
- private final FooProperties properties;
+ private final AcmeProperties properties;
@Autowired
- public MyService(FooProperties properties) {
+ public MyService(AcmeProperties properties) {
this.properties = properties;
}
@@ -133,5 +133,3 @@ public class MyService {
}
```
**注** 使用`@ConfigurationProperties`能够产生可被IDEs使用的元数据文件,来为你自己的键值提供自动补全,具体参考[Appendix B, Configuration meta-data](../X. Appendices/B. Configuration meta-data.md)。
-
-**此章节翻译的不好,后续整理***
diff --git a/IV. Spring Boot features/24.7.1. Third-party Configuration.md b/IV. Spring Boot features/24.7.1. Third-party Configuration.md
new file mode 100644
index 00000000..3a9dc764
--- /dev/null
+++ b/IV. Spring Boot features/24.7.1. Third-party Configuration.md
@@ -0,0 +1,13 @@
+### 24.7.1. 第三方配置
+
+`@ConfigurationProperties`不仅可以注解在类上,也可以注解在public `@Bean`方法上,当你需要为不受控的第三方组件绑定属性时,该方法将非常有用。
+
+为了从`Environment`属性中配置一个bean,你需要使用`@ConfigurationProperties`注解该bean:
+```java
+@ConfigurationProperties(prefix = "another")
+@Bean
+public AnotherComponent anotherComponent() {
+ ...
+}
+```
+和之前的`AcmeProperties`的示例方式相同,所有以`another`为前缀的属性定义都会被映射到`AnotherComponent`上。
diff --git a/IV. Spring Boot features/24.7.1. Third-party configuration.md b/IV. Spring Boot features/24.7.1. Third-party configuration.md
deleted file mode 100644
index 39ca58af..00000000
--- a/IV. Spring Boot features/24.7.1. Third-party configuration.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 24.7.1. 第三方配置
-
-`@ConfigurationProperties`不仅可以注解在类上,也可以注解在public `@Bean`方法上,当你需要为不受控的第三方组件绑定属性时,该方法将非常有用。
-
-为了从`Environment`属性中配置一个bean,你需要使用`@ConfigurationProperties`注解该bean:
-```java
-@ConfigurationProperties(prefix = "bar")
-@Bean
-public BarComponent barComponent() {
- ...
-}
-```
-和上面`FooProperties`的示例方式相同,所有以`bar`为前缀的属性定义都会被映射到`BarComponent`上。
diff --git a/IV. Spring Boot features/24.7.2. Relaxed Binding.md b/IV. Spring Boot features/24.7.2. Relaxed Binding.md
new file mode 100644
index 00000000..0d8e1dc3
--- /dev/null
+++ b/IV. Spring Boot features/24.7.2. Relaxed Binding.md
@@ -0,0 +1,44 @@
+### 24.7.2. Relaxed绑定
+
+Spring Boot将`Environment`属性绑定到`@ConfigurationProperties` beans时会使用一些宽松的规则,所以`Environment`属性名和bean属性名不需要精确匹配。常见的示例中有用的包括虚线分割(比如,`context-path`绑定到`contextPath`),将environment属性转为大写字母(比如,`PORT`绑定`port`)。
+
+例如,考虑以下`@ConfigurationProperties`类:
+```java
+@ConfigurationProperties(prefix="acme.my-project.person")
+public class OwnerProperties {
+
+ private String firstName;
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+}
+```
+在之前的例子里,下面的属性名都能使用:
+
+表格 24.1. relaxed绑定
+
+| 属性 | 说明 |
+| -------- | :----- |
+|`acme.my-project.person.firstName`|标准驼峰命名语法|
+|`acme.my-project.person.first-name`|短横线隔开表示,推荐用于`.properties`和`.yml`文件中|
+|`acme.my-project.person.first_name`|下划线表示,用于`.properties`和`.yml`文件的可选格式|
+|`ACME_MYPROJECT_PERSON_FIRSTNAME`|大写形式,推荐用于系统环境变量|
+
+**注** 注解的`前缀`值必须用短横线隔开表示,即小写并用`-`隔开,比如`acme.my-project.person`。
+
+表格 24.2. 各个属性源的relaxed绑定规则
+
+| 属性源 | Simple | List |
+| -------- | :----- | :----- |
+|Properties文件|驼峰命名法,短横线隔开表示,下划线表示|使用`[ ]`的标准list语法,或者由逗号分隔的值|
+|YAML文件|驼峰命名法,短横线隔开表示,下划线表示|标准的YAML list语法,或者由逗号分隔的值|
+|环境变量|下划线作为分隔符的大写格式。`_`不应当用在属性名上|被下划线环绕的数值。比如:`MY_ACME_1_OTHER = my.acme[1].other`|
+|系统属性|驼峰命名法,短横线隔开表示,下划线表示|使用`[ ]`的标准list语法,或者由逗号分隔的值|
+
+**提示** 我们推荐:当可能时,属性用小写短横线隔开的格式储存。比如,`my.property-name=acme`
diff --git a/IV. Spring Boot features/24.7.2. Relaxed binding.md b/IV. Spring Boot features/24.7.2. Relaxed binding.md
deleted file mode 100644
index 4544f2a6..00000000
--- a/IV. Spring Boot features/24.7.2. Relaxed binding.md
+++ /dev/null
@@ -1,42 +0,0 @@
-### 24.7.2. Relaxed绑定
-
-Spring Boot将`Environment`属性绑定到`@ConfigurationProperties` beans时会使用一些宽松的规则,所以`Environment`属性名和bean属性名不需要精确匹配。常见的示例中有用的包括虚线分割(比如,`context-path`绑定到`contextPath`),将environment属性转为大写字母(比如,`PORT`绑定`port`)。
-
-例如,给定以下`@ConfigurationProperties`类:
-```java
-@ConfigurationProperties(prefix="person")
-public class OwnerProperties {
-
- private String firstName;
-
- public String getFirstName() {
- return this.firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
-}
-```
-下面的属性名都能使用:
-
-表格 24.1. relaxed绑定
-| 属性 | 说明 |
-| -------- | :----- |
-|`person.firstName`|标准驼峰命名语法|
-|`person.first-name`|短横线隔开表示,推荐用于`.properties`和`.yml`文件中|
-|`person.first_name`|下划线表示,用于`.properties`和`.yml`文件的可选格式|
-|`PERSON_FIRST_NAME`|大写形式,推荐用于系统环境变量|
-
-**注** 注解的`前缀`值必须用短横线隔开表示,即小写并用`-`隔开。
-
-表格 24.2. 各个属性源的relaxed绑定规则
-| 属性源 | Simple | List |
-| -------- | :----- |
-|Properties文件|驼峰命名法,短横线隔开表示,下划线表示|使用`[ ]`的标准list语法,或者由逗号分隔的值|
-|YAML文件|驼峰命名法,短横线隔开表示,下划线表示|标准的YAML list语法,或者由逗号分隔的值|
-|环境变量|下划线作为分隔符的大写格式。`_`不应当用在属性名上|被下划线环绕的数值。比如:`MY_FOO_1_BAR = my.foo[1].bar`|
-|系统属性|驼峰命名法,短横线隔开表示,下划线表示|使用`[ ]`的标准list语法,或者由逗号分隔的值|
-
-**提示** 我们推荐:当可能时,属性用小写短横线隔开的格式储存。比如,`my.property-name=foo`
\ No newline at end of file
diff --git a/IV. Spring Boot features/24.7.3. Properties Conversion.md b/IV. Spring Boot features/24.7.3. Properties Conversion.md
new file mode 100644
index 00000000..7ff906c1
--- /dev/null
+++ b/IV. Spring Boot features/24.7.3. Properties Conversion.md
@@ -0,0 +1,56 @@
+### 24.7.3 属性转换
+
+将外部应用配置绑定到`@ConfigurationProperties` beans时,Spring Boot会尝试将属性强制转换为正确的类型。如果需要自定义类型转换器,你可以提供一个`ConversionService` bean(名为`conversionService`的bean),或自定义属性编辑器(通过`CustomEditorConfigurer` bean),或自定义`Converters`(bean定义时需要注解`@ConfigurationPropertiesBinding`)。
+
+**注** 由于该bean在应用程序生命周期的早期就需要使用,所以确保限制你的`ConversionService`使用的依赖。通常,在创建时期任何你需要的依赖可能都没完全初始化。如果强制配置关键字不需要它,而且只依赖满足`@ConfigurationPropertiesBinding`的自定义的转换器,你可能想要重命名自定义的`ConversionService`。
+
+**时间段转换**
+
+Spring Boot对表达时间段有专门的支持。 如果你暴露了`java.time.Duration`属性,可用下列格式的应用属性:
+
+- 常规的 `long`表示(默认单位为毫秒,除非指定了`@DefaultUnit`)
+- [`java.util.Duration`使用的](https://docs.oracle.com/javase/8/docs/api//java/time/Duration.html#parse-java.lang.CharSequence-)标准的ISO-8601格式
+- 组合了值与单位的更加易读的格式(比如`10s`表示10秒)
+
+考虑下面的例子:
+```java
+@ConfigurationProperties("app.system")
+public class AppSystemProperties {
+
+ @DurationUnit(ChronoUnit.SECONDS)
+ private Duration sessionTimeout = Duration.ofSeconds(30);
+
+ private Duration readTimeout = Duration.ofMillis(1000);
+
+ public Duration getSessionTimeout() {
+ return this.sessionTimeout;
+ }
+
+ public void setSessionTimeout(Duration sessionTimeout) {
+ this.sessionTimeout = sessionTimeout;
+ }
+
+ public Duration getReadTimeout() {
+ return this.readTimeout;
+ }
+
+ public void setReadTimeout(Duration readTimeout) {
+ this.readTimeout = readTimeout;
+ }
+
+}
+```
+为了将会话超时指定为30秒,`30`, `PT30S`和 `30s`都是等价的。将读取超时指定为500毫秒,可以用下列格式里的任何一种:`500`, `PT0.5S`与`500ms`。
+
+你也可以使用任何支持的单位:
+
+- ns用于纳秒
+- ms用于毫秒
+- s用于秒
+- m用于分
+- h用于小时
+- d应用日
+
+默认单位是毫秒,可以使用`@DefaultUnit`重写。
+
+**注** 如果你正在升级之前的版本,之前的版本简单地使用`Long`来表达时间段,如果切换到`Duration`时不是毫秒,要确保定义了单位(使用`@DefaultUnit`)。这样做的话,在支持更加丰富的格式的同时,升级也能更加透明。
\ No newline at end of file
diff --git a/IV. Spring Boot features/24.7.3. Properties conversion.md b/IV. Spring Boot features/24.7.3. Properties conversion.md
deleted file mode 100644
index b6382c15..00000000
--- a/IV. Spring Boot features/24.7.3. Properties conversion.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 24.7.3 属性转换
-
-将外部应用配置绑定到`@ConfigurationProperties` beans时,Spring会尝试将属性强制转换为正确的类型。如果需要自定义类型转换器,你可以提供一个`ConversionService` bean(bean id为`conversionService`),或自定义属性编辑器(通过`CustomEditorConfigurer` bean),或自定义`Converters`(bean定义时需要注解`@ConfigurationPropertiesBinding`)。
-
-**注** 由于该bean在应用程序生命周期的早期就需要使用,所以确保限制你的`ConversionService`使用的依赖。通常,在创建时期任何你需要的依赖可能都没完全初始化。
diff --git a/IV. Spring Boot features/24.7.4. @ConfigurationProperties Validation.md b/IV. Spring Boot features/24.7.4. @ConfigurationProperties Validation.md
index 6d985aef..cbf6d5ed 100644
--- a/IV. Spring Boot features/24.7.4. @ConfigurationProperties Validation.md
+++ b/IV. Spring Boot features/24.7.4. @ConfigurationProperties Validation.md
@@ -1,10 +1,10 @@
### 24.7.4. @ConfigurationProperties校验
-Spring Boot将尝试校验`@ConfigurationProperties`类,只要它们标注了Spring的`@Validated`。你可以在你的配置类中直接使用JSR-303 `javax.validation`约束标注。确保在你的类路径中存在适用的JSR-303实现,,再添加约束标注在你的域中:
+Spring Boot会尝试校验`@ConfigurationProperties`类,只要它们标注了Spring的`@Validated`。你可以在你的配置类中直接使用JSR-303 `javax.validation`约束标注。确保在你的类路径中存在适用的JSR-303实现,再添加约束标注在你的域中:
```java
-@ConfigurationProperties(prefix="foo")
+@ConfigurationProperties(prefix="acme")
@Validated
-public class FooProperties {
+public class AcmeProperties {
@NotNull
private InetAddress remoteAddress;
@@ -13,11 +13,14 @@ public class FooProperties {
}
```
+**注** 你也可以通过标注`@Bean`方法触发验证,用`@Validated`创建配置属性。
+
+尽管在绑定后,内嵌属性也会被验证,但还是把相关的域标注上`@Valid`不失为一种良好的实践。这确保了即使没有找到内嵌属性,验证还是会被触发。下面的例子建立在之前的`AcmeProperties`示例之上:
为了校验内嵌属性的值,你需要使用`@Valid`注解关联的字段以触发它的校验,例如,建立在上面的FooProperties示例之上:
```java
-@ConfigurationProperties(prefix="connection")
+@ConfigurationProperties(prefix="acme")
@Validated
-public class FooProperties {
+public class AcmeProperties {
@NotNull
private InetAddress remoteAddress;
@@ -38,6 +41,6 @@ public class FooProperties {
}
```
-你也可以通过创建一个叫做`configurationPropertiesValidator`的bean来添加自定义的Spring `Validator`。`@Bean`方法需要声明为`static`,因为配置属性校验器在应用程序生命周期中创建的比较早,将`@Bean`方法声明为`static`允许该bean在创建时不需要实例化`@Configuration`类,从而避免了早期实例化(early instantiation)的所有问题。相关的示例可以看[这里](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-samples/spring-boot-sample-property-validation)。
+你也可以通过创建一个叫做`configurationPropertiesValidator`的bean来添加自定义的Spring `Validator`。`@Bean`方法需要声明为`static`,因为配置属性校验器在应用程序生命周期中创建的比较早,将`@Bean`方法声明为`static`允许该bean在创建时不需要实例化`@Configuration`类,从而避免了早期实例化(early instantiation)的所有问题。相关的示例可以看[这里](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-samples/spring-boot-sample-property-validation)。
-**注** `spring-boot-actuator`模块包含一个暴露所有`@ConfigurationProperties` beans的端点(endpoint),通过浏览器打开`/application/configprops`进行浏览,或使用等效的JMX端点,具体参考[Production ready features](../V. Spring Boot Actuator/49. Endpoints.md)。
+**注** `spring-boot-actuator`模块包含一个暴露所有`@ConfigurationProperties` beans的端点(endpoint),通过浏览器打开`/actuator/configprops`进行浏览,或使用等效的JMX端点,具体参考[Production ready features](../V. Spring Boot Actuator/50. Endpoints.md)。
diff --git a/IV. Spring Boot features/24.7.5. @ConfigurationProperties vs. @Value.md b/IV. Spring Boot features/24.7.5. @ConfigurationProperties vs. @Value.md
index 1c523e22..d3a81f27 100644
--- a/IV. Spring Boot features/24.7.5. @ConfigurationProperties vs. @Value.md
+++ b/IV. Spring Boot features/24.7.5. @ConfigurationProperties vs. @Value.md
@@ -1,11 +1,11 @@
### 24.7.5 @ConfigurationProperties vs. @Value
-`@Value`是Spring容器的一个核心特性,它没有提供跟type-safe Configuration Properties相同的特性。下面的表格总结了`@ConfigurationProperties`和`@Value`支持的特性:
+`@Value`标注是Spring容器的一个核心特性,它没有提供跟类型安全的配置属性相同的特性。下面的表格总结了`@ConfigurationProperties`和`@Value`支持的特性:
|特性|`@ConfigurationProperties`|`@Value`|
|---|---|---|
-|[Relaxed绑定](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-relaxed-binding)|Yes|No|
-|[Meta-data支持](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#configuration-metadata)|Yes|No|
+|[Relaxed绑定](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-relaxed-binding)|Yes|No|
+|[Meta-data支持](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#configuration-metadata)|Yes|No|
|`SpEL`表达式|No|Yes|
-如果你为自己的组件定义了一系列的配置keys,我们建议你将它们以`@ConfigurationProperties`注解的POJO进行分组。由于`@Value`不支持relaxed绑定,所以如果你使用环境变量提供属性值的话,它就不是很好的选择。最后,尽管`@Value`可以写`SpEL`表达式,但这些表达式不会处理来自[Application属性文件](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-application-property-files)的属性。
+如果你为自己的组件定义了一系列的配置keys,我们建议你将它们以`@ConfigurationProperties`注解的POJO进行分组。由于`@Value`不支持relaxed绑定,所以如果你使用环境变量提供属性值的话,它就不是很好的选择。最后,尽管`@Value`可以写`SpEL`表达式,但这些表达式不会处理来自[Application属性文件](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-application-property-files)的属性。
diff --git a/IV. Spring Boot features/25. Profiles.md b/IV. Spring Boot features/25. Profiles.md
index c35f8272..4606d080 100644
--- a/IV. Spring Boot features/25. Profiles.md
+++ b/IV. Spring Boot features/25. Profiles.md
@@ -1,4 +1,5 @@
### 25. Profiles
+
Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只在特定的环境下生效。任何`@Component`或`@Configuration`都能注解`@Profile`,从而限制加载它的时机:
```java
@Configuration
@@ -9,7 +10,7 @@ public class ProductionConfiguration {
}
```
-以正常的Spring方式,你可以使用`spring.profiles.active`的`Environment`属性来指定哪个配置生效。你可以使用通常的任何方式来指定该属性,例如,可以将它包含到`application.properties`中:
+你可以使用`spring.profiles.active`的`Environment`属性来指定哪个配置生效。你可以使用在这一章的前面描述过的任何方式来指定该属性。例如,可以将它包含到`application.properties`中:
```java
spring.profiles.active=dev,hsqldb
```
diff --git a/IV. Spring Boot features/25.1. Adding Active Profiles.md b/IV. Spring Boot features/25.1. Adding Active Profiles.md
new file mode 100644
index 00000000..32fde7ba
--- /dev/null
+++ b/IV. Spring Boot features/25.1. Adding Active Profiles.md
@@ -0,0 +1,17 @@
+### 25.1. 添加激活的配置(profiles)
+
+`spring.profiles.active`属性和其他属性一样都遵循相同的排列规则:优先级最高的`PropertySource`获胜,也就是说,你可以在`application.properties`中指定生效的配置,然后使用命令行开关替换它们。
+
+有时,将profile-specific的属性添加到激活的配置中而不是直接替换它们是有好处的。`spring.profiles.include`属性可以用来无条件的添加激活的配置,而`SpringApplication`的入口点也提供了一个用于设置其他配置的Java API,通过它设置的active配置优先级高于`spring.profiles.active`,具体参考`setAdditionalProfiles()`方法。
+
+例如,当一个应用使用下面的属性,并用`--spring.profiles.active=prod`开关运行,那`proddb`和`prodmq` profiles也会激活:
+```java
+---
+my.property: fromyamlfile
+---
+spring.profiles: prod
+spring.profiles.include:
+ - proddb
+ - prodmq
+```
+**注** `spring.profiles`属性可以定义到YAML文档中,以决定何时将该文档包含进配置,具体参考[章节 74.7 根据环境改变配置](../IX. ‘How-to’ guides/74.7 Change configuration depending on the environment.md)
diff --git a/IV. Spring Boot features/25.1. Adding active profiles.md b/IV. Spring Boot features/25.1. Adding active profiles.md
deleted file mode 100644
index 8eeed3ae..00000000
--- a/IV. Spring Boot features/25.1. Adding active profiles.md
+++ /dev/null
@@ -1,17 +0,0 @@
-### 25.1. 添加激活的配置(profiles)
-
-`spring.profiles.active`属性和其他属性一样都遵循相同的排列规则,优先级最高的`PropertySource`获胜,也就是说,你可以在`application.properties`中指定生效的配置,然后使用命令行开关替换它们。
-
-有时,将profile-specific的属性添加到激活的配置中而不是直接替换它们是有好处的。`spring.profiles.include`属性可以用来无条件的添加激活的配置,而`SpringApplication`的入口点也提供了一个用于设置其他配置的Java API,通过它设置的active配置优先级高于`spring.profiles.active`,具体参考`setAdditionalProfiles()`方法。
-
-例如,当一个应用使用下面的属性,并用`--spring.profiles.active=prod`开关运行,那`proddb`和`prodmq` profiles也会激活:
-```java
----
-my.property: fromyamlfile
----
-spring.profiles: prod
-spring.profiles.include:
- - proddb
- - prodmq
-```
-**注** `spring.profiles`属性可以定义到YAML文档中,以决定何时将该文档包含进配置,具体参考[章节 73.7,根据环境改变配置](../IX. ‘How-to’ guides/73.7. Change configuration depending on the environment.md)
diff --git a/IV. Spring Boot features/25.2. Programmatically setting profiles.md b/IV. Spring Boot features/25.2. Programmatically Setting Profiles.md
similarity index 100%
rename from IV. Spring Boot features/25.2. Programmatically setting profiles.md
rename to IV. Spring Boot features/25.2. Programmatically Setting Profiles.md
diff --git a/IV. Spring Boot features/25.3. Profile specific configuration files.md b/IV. Spring Boot features/25.3. Profile specific configuration files.md
deleted file mode 100644
index 9f71dcd9..00000000
--- a/IV. Spring Boot features/25.3. Profile specific configuration files.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 25.3. Profile-specific配置文件
-
-Profile-specific的配置,不管是`application.properties`(或`application.yml`),还是通过`@ConfigurationProperties`引用的文件都是被当作文件来加载的,具体参考[Section 24.3, “Profile specific properties”](24.4. Profile-specific properties.md)。
diff --git a/IV. Spring Boot features/25.3. Profile-specific Configuration Files.md b/IV. Spring Boot features/25.3. Profile-specific Configuration Files.md
new file mode 100644
index 00000000..83acc750
--- /dev/null
+++ b/IV. Spring Boot features/25.3. Profile-specific Configuration Files.md
@@ -0,0 +1,3 @@
+### 25.3. Profile-specific配置文件
+
+Profile-specific的配置,不管是`application.properties`(或`application.yml`),还是通过`@ConfigurationProperties`引用的文件都是被当作文件来加载的,具体参考[Section 24.4, “Profile-specific Properties”](24.4. Profile-specific Properties.md)。
diff --git a/IV. Spring Boot features/26. Logging.md b/IV. Spring Boot features/26. Logging.md
index 285428fd..f0d8422b 100644
--- a/IV. Spring Boot features/26. Logging.md
+++ b/IV. Spring Boot features/26. Logging.md
@@ -1,6 +1,6 @@
### 26. 日志
Spring Boot内部日志系统使用的是[Commons Logging](http://commons.apache.org/logging),但开放底层的日志实现,默认为会[Java Util Logging](http://docs.oracle.com/javase/7/docs/api/java/util/logging/package-summary.html), [Log4J](http://logging.apache.org/log4j/), [Log4J2](http://logging.apache.org/log4j/2.x/)和[Logback](http://logback.qos.ch/)提供配置。每种情况下都预先配置使用控制台输出,也可以使用可选的文件输出。
-默认情况下,如果你使用'Starters',那么就会使用Logback记录日志。为了确保使用Java Util Logging, Commons Logging, Log4J或SLF4J的依赖库能够正常工作,相应的Logback路由也会包含进来。
+默认情况下,如果你使用“Starters”,那么就会使用Logback记录日志。为了确保使用Java Util Logging, Commons Logging, Log4J或SLF4J的依赖库能够正常工作,相应的Logback路由也会包含进来。
**注** 如果上面的列表看起来令人困惑,不要担心,Java有很多可用的日志框架。通常,你不需要改变日志依赖,Spring Boot默认的就能很好的工作。
diff --git a/IV. Spring Boot features/26.1. Log Format.md b/IV. Spring Boot features/26.1. Log Format.md
new file mode 100644
index 00000000..7bca9623
--- /dev/null
+++ b/IV. Spring Boot features/26.1. Log Format.md
@@ -0,0 +1,21 @@
+### 26.1. 日志格式
+
+Spring Boot默认的日志输出格式如下:
+```java
+2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
+2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
+2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
+2014-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
+2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
+```
+输出的节点(items)如下:
+
+1. 日期和时间:精确到毫秒,且易于排序。
+2. 日志级别:`ERROR`, `WARN`, `INFO`, `DEBUG` 或 `TRACE`。
+3. Process ID。
+4. `---`分隔符,用于区分实际日志信息开头。
+5. 线程名:包括在方括号中(控制台输出可能会被截断)。
+6. 日志名:通常是源class的类名(缩写)。
+7. 日志信息。
+
+**注** Logback没有`FATAL`级别。它会映射到`ERROR`。
diff --git a/IV. Spring Boot features/26.1. Log format.md b/IV. Spring Boot features/26.1. Log format.md
deleted file mode 100644
index f20d6bca..00000000
--- a/IV. Spring Boot features/26.1. Log format.md
+++ /dev/null
@@ -1,21 +0,0 @@
-### 26.1. 日志格式
-
-Spring Boot默认的日志输出格式如下:
-```java
-2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
-2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
-2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
-2014-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
-2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
-```
-输出的节点(items)如下:
-
-1. 日期和时间 - 精确到毫秒,且易于排序。
-2. 日志级别 - `ERROR`, `WARN`, `INFO`, `DEBUG` 或 `TRACE`。
-3. Process ID。
-4. `---`分隔符,用于区分实际日志信息开头。
-5. 线程名 - 包括在方括号中(控制台输出可能会被截断)。
-6. 日志名 - 通常是源class的类名(缩写)。
-7. 日志信息。
-
-**注** Logback没有`FATAL`级别,它会映射到`ERROR`。
diff --git a/IV. Spring Boot features/26.2. Console output.md b/IV. Spring Boot features/26.2. Console Output.md
similarity index 100%
rename from IV. Spring Boot features/26.2. Console output.md
rename to IV. Spring Boot features/26.2. Console Output.md
diff --git a/IV. Spring Boot features/26.2.1. Color-coded Output.md b/IV. Spring Boot features/26.2.1. Color-coded Output.md
new file mode 100644
index 00000000..f3f5cd53
--- /dev/null
+++ b/IV. Spring Boot features/26.2.1. Color-coded Output.md
@@ -0,0 +1,31 @@
+### 26.2.1 Color-coded输出
+如果你的终端支持ANSI,Spring Boot将使用彩色编码(color output)输出日志以增强可读性,你可以将`spring.output.ansi.enabled`设置为一个[支持的值](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/ansi/AnsiOutput.Enabled.html)来覆盖默认设置。
+
+彩色编码(Color coding)使用`%clr`表达式进行配置,在其最简单的形式中,转换器会根据日志级别使用不同的颜色输出日志,例如:
+```properties
+%clr(%5p)
+```
+下面的表格描述了日志级别到颜色的映射:
+
+|级别|颜色|
+|---|---|
+|`FATAL`|Red|
+|`ERROR`|Red|
+|`WARN`|Yellow|
+|`INFO`|Green|
+|`DEBUG`|Green|
+|`TRACE`|Green|
+
+另外,在转换时你可以设定日志展示的颜色或样式,例如,让文本显示成黄色:
+```properties
+%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
+```
+支持的颜色,样式如下:
+
+* `blue`
+* `cyan`
+* `faint`
+* `green`
+* `magenta`
+* `red`
+* `yellow`
diff --git a/IV. Spring Boot features/26.2.1. Color-coded output.md b/IV. Spring Boot features/26.2.1. Color-coded output.md
deleted file mode 100644
index 5faa7e5f..00000000
--- a/IV. Spring Boot features/26.2.1. Color-coded output.md
+++ /dev/null
@@ -1,33 +0,0 @@
-### 26.2.1 Color-coded输出
-如果你的终端支持ANSI,Spring Boot将使用彩色编码(color output)输出日志以增强可读性,你可以将`spring.output.ansi.enabled`设置为一个[支持的值](http://docs.spring.io/spring-boot/docs/2.0.0.M5/api/org/springframework/boot/ansi/AnsiOutput.Enabled.html)来覆盖默认设置。
-
-彩色编码(Color coding)使用`%clr`表达式进行配置,在其最简单的形式中,转换器会根据日志级别使用不同的颜色输出日志,例如:
-```properties
-%clr(%5p)
-```
-日志级别到颜色的映射如下:
-
-|Level|Color|
-|---|---|
-|`FATAL`|Red|
-|`ERROR`|Red|
-|`WARN`|Yellow|
-|`INFO`|Green|
-|`DEBUG`|Green|
-|`TRACE`|Green|
-
-另外,在转换时你可以设定日志展示的颜色或样式,例如,让文本显示成黄色:
-```properties
-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}
-```
-支持的颜色,样式如下:
-
-* `blue`
-* `cyan`
-* `faint`
-* `green`
-* `magenta`
-* `red`
-* `yellow`
-
-
diff --git a/IV. Spring Boot features/26.3. File Output.md b/IV. Spring Boot features/26.3. File Output.md
new file mode 100644
index 00000000..fd26add6
--- /dev/null
+++ b/IV. Spring Boot features/26.3. File Output.md
@@ -0,0 +1,17 @@
+### 26.3. 文件输出
+
+默认情况下,Spring Boot只会将日志记录到控制台,而不写进日志文件,如果需要,你可以设置`logging.file`或`logging.path`属性(例如`application.properties`)。
+
+下表展示如何组合使用`logging.*`:
+
+|logging.file|logging.path| 示例 | 描述 |
+| -------- | :----- | :----- | :-----|
+| (none) | (none) | | 只记录到控制台 |
+|Specific file|(none)|my.log|写到特定的日志文件,名称可以是精确的位置或相对于当前目录|
+|(none)|Specific directory|/var/log|写到特定目录下的`spring.log`里,名称可以是精确的位置或相对于当前目录|
+
+日志文件每达到10MB就会被分割,跟控制台一样,默认记录`ERROR`, `WARN`和`INFO`级别的信息。可以使用`logging.file.max-size`属性改变大小限制。已经分割归档好的文件会无限期地保存下去,除非设置了`logging.file.max-history`属性。
+
+**注** 日志系统在应用生命周期的早期初始化。因此,日志属性不能在通过`@PropertySource`标注加载的属性文件里找到。
+
+**注** 日志属性独立于实际的日志基础设施。结果就是,特定的配置key(比如Logback的`logback.configurationFile`)不由Spring Boot管理。
diff --git a/IV. Spring Boot features/26.3. File output.md b/IV. Spring Boot features/26.3. File output.md
deleted file mode 100644
index b451b50c..00000000
--- a/IV. Spring Boot features/26.3. File output.md
+++ /dev/null
@@ -1,13 +0,0 @@
-### 26.3. 文件输出
-
-默认情况下,Spring Boot只会将日志记录到控制台,而不写进日志文件,如果需要,你可以设置`logging.file`或`logging.path`属性(例如`application.properties`)。
-
-下表展示如何组合使用`logging.*`:
-
-|logging.file|logging.path| 示例 | 描述 |
-| -------- | :----- | :----- | :-----|
-| (none) | (none) | | 只记录到控制台 |
-|Specific file|(none)|my.log|写到特定的日志文件,名称可以是精确的位置或相对于当前目录|
-|(none)|Specific directory|/var/log|写到特定目录下的`spring.log`里,名称可以是精确的位置或相对于当前目录|
-
-日志文件每达到10MB就会被分割,跟控制台一样,默认记录`ERROR`, `WARN`和`INFO`级别的信息。
diff --git a/IV. Spring Boot features/26.4. Log Levels.md b/IV. Spring Boot features/26.4. Log Levels.md
index d91c5b6d..43ee27e2 100644
--- a/IV. Spring Boot features/26.4. Log Levels.md
+++ b/IV. Spring Boot features/26.4. Log Levels.md
@@ -1,11 +1,10 @@
### 26.4. 日志级别
-所有Spring Boot支持的日志系统都可以在Spring `Environment`中设置级别(`application.properties`里也一样),设置格式为'logging.level.*=LEVEL',其中`LEVEL`是`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`, `OFF`之一:
+所有Spring Boot支持的日志系统都可以在Spring `Environment`中设置级别(`application.properties`里也一样),设置格式为logging.level.=,其中`level`是`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`, `OFF`之一。`root`记录器可以使用`logging.level.root`配置。
-以下是`application.properties`示例:
+下面的例子展示了`application.properties`里可能的日志设置:
```properties
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
```
-**注** 默认情况,Spring Boot会重新映射Thymeleaf的`INFO`信息到`DEBUG`级别,这能减少标准日志输出的噪声。查看[LevelRemappingAppender](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot/src/main/java/org/springframework/boot/logging/logback/LevelRemappingAppender.java)可以按自己的配置设置映射。
diff --git a/IV. Spring Boot features/26.5. Custom Log Configuration.md b/IV. Spring Boot features/26.5. Custom Log Configuration.md
new file mode 100644
index 00000000..77a94a31
--- /dev/null
+++ b/IV. Spring Boot features/26.5. Custom Log Configuration.md
@@ -0,0 +1,49 @@
+### 26.5. 自定义日志配置
+
+通过将相应的库添加到classpath可以激活各种日志系统,然后在classpath根目录下提供合适的配置文件可以进一步定制日志系统,配置文件也可以通过Spring `Environment`的`logging.config`属性指定。
+
+使用`org.springframework.boot.logging.LoggingSystem`系统属性可以强制Spring Boot使用指定的日志系统,该属性值需要是`LoggingSystem`实现类的全限定名,如果值为`none`,则彻底禁用Spring Boot的日志配置。
+
+**注** 由于日志初始化早于`ApplicationContext`的创建,所以不可能通过`@PropertySources`指定的Spring `@Configuration`文件控制日志,系统属性和Spring Boot外部化配置可以正常工作。
+
+以下文件会根据你选择的日志系统进行加载:
+
+| 日志系统 | 定制配置 |
+| -------- | :-----: |
+|Logback|`logback-spring.xml`,`logback-spring.groovy`,`logback.xml`或`logback.groovy`|
+|Log4j|`log4j.properties`或`log4j.xml`|
+|Log4j2|`log4j2-spring.xml`或`log4j2.xml`|
+|JDK (Java Util Logging)|`logging.properties`|
+
+**注** 如果可能的话,建议你使用`-spring`变种形式定义日志配置(例如,使用`logback-spring.xml`而不是`logback.xml`)。如果你使用标准的配置路径,Spring可能不能够完全控制日志初始化。
+
+**注** Java Util Logging从可执行jar运行时会导致一些已知的类加载问题,我们建议尽可能不使用它。
+
+以下是从Spring `Envrionment`转换为System properties的一些有助于定制的配置属性:
+
+| Spring Environment| System Property| Comments |
+| -------- | :-----: | :----: |
+|`logging.exception-conversion-word`|`LOG_EXCEPTION_CONVERSION_WORD`|记录异常使用的关键字|
+|`logging.file`|`LOG_FILE`|如果指定就会在默认的日志配置中使用|
+|`logging.file.max-size`|`LOG_FILE_MAX_SIZE`|最大日志文件大小(如果LOG_FILE启用)。(只支持默认的Logback设置)|
+|`logging.file.max-history`|`LOG_FILE_MAX_HISTORY`|保留的归档文件的最大数量(如果LOG_FILE启用)。(只支持默认的Logback设置)|
+|`logging.path`|`LOG_PATH`|如果指定就会在默认的日志配置中使用|
+|`logging.pattern.console`|`CONSOLE_LOG_PATTERN`|日志输出到控制台(stdout)时使用的模式(只支持默认的logback设置)|
+|`logging.pattern.dateformat`|`LOG_DATEFORMAT_PATTERN`|日志日期格式的输出格式(只支持默认的logback设置)|
+|`logging.pattern.file`|`FILE_LOG_PATTERN`|日志输出到文件时使用的模式(如果LOG_FILE启用,只支持默认的logback设置)|
+|`logging.pattern.level`|`LOG_LEVEL_PATTERN`|用来渲染日志级别的格式(默认`%5p`,只支持默认的logback设置)|
+|`PID`|`PID`|当前的处理进程(process)ID(能够找到,且还没有用作OS环境变量)|
+
+所有支持的日志系统在解析配置文件时都能获取系统属性的值,具体可以参考`spring-boot.jar`中的默认配置。
+
+- [Logback](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml)
+- [Log4j 2](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2/log4j2.xml)
+- [Java Util logging](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/java/logging-file.properties)
+
+**注** 如果想在日志属性中使用占位符,你需要使用[Spring Boot的语法](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-external-config-placeholders-in-properties),而不是底层框架的语法。尤其是使用Logback时,你需要使用`:`作为属性名和默认值的分隔符,而不是`:-`。
+
+**注** 通过覆盖`LOG_LEVEL_PATTERN`(Logback对应`logging.pattern.level`),你可以向日志中添加MDC和其他ad-hoc的内容。例如,将该值设置为`logging.pattern.level=user:%X{user} %5p`,则默认日志格式将包含一个"user"的MDC实体,如果存在的话,比如:
+```properties
+2015-09-30 12:30:04.031 user:juergen INFO 22174 --- [ nio-8080-exec-0] demo.Controller
+Handling authenticated request
+```
diff --git a/IV. Spring Boot features/26.5. Custom log configuration.md b/IV. Spring Boot features/26.5. Custom log configuration.md
deleted file mode 100644
index d071a51a..00000000
--- a/IV. Spring Boot features/26.5. Custom log configuration.md
+++ /dev/null
@@ -1,41 +0,0 @@
-### 26.5. 自定义日志配置
-通过将相应的库添加到classpath可以激活各种日志系统,然后在classpath根目录下提供合适的配置文件可以进一步定制日志系统,配置文件也可以通过Spring `Environment`的`logging.config`属性指定。
-
-使用`org.springframework.boot.logging.LoggingSystem`系统属性可以强制Spring Boot使用指定的日志系统,该属性值需要是`LoggingSystem`实现类的全限定名,如果值为`none`,则彻底禁用Spring Boot的日志配置。
-
-**注** 由于日志初始化早于`ApplicationContext`的创建,所以不可能通过`@PropertySources`指定的Spring `@Configuration`文件控制日志,系统属性和Spring Boot外部化配置可以正常工作。
-
-以下文件会根据你选择的日志系统进行加载:
-
-| 日志系统 | 定制配置 |
-| -------- | :-----: |
-|Logback|`logback-spring.xml`,`logback-spring.groovy`,`logback.xml`或`logback.groovy`|
-|Log4j|`log4j.properties`或`log4j.xml`|
-|Log4j2|`log4j2-spring.xml`或`log4j2.xml`|
-|JDK (Java Util Logging)|`logging.properties`|
-
-**注** 如果可能的话,建议你使用`-spring`变种形式定义日志配置(例如,使用`logback-spring.xml`而不是`logback.xml`)。如果你使用标准的配置路径,Spring可能不能够完全控制日志初始化。
-
-**注** Java Util Logging从可执行jar运行时会导致一些已知的类加载问题,我们建议尽可能不使用它。
-
-以下是从Spring `Envrionment`转换为System properties的一些有助于定制的配置属性:
-
-| Spring Environment| System Property| Comments |
-| -------- | :-----: | :----: |
-|`logging.exception-conversion-word`|`LOG_EXCEPTION_CONVERSION_WORD`|记录异常使用的关键字|
-|`logging.file`|`LOG_FILE`|如果指定就会在默认的日志配置中使用|
-|`logging.path`|`LOG_PATH`|如果指定就会在默认的日志配置中使用|
-|`logging.pattern.console`|`CONSOLE_LOG_PATTERN`|日志输出到控制台(stdout)时使用的模式(只支持默认的logback设置)|
-|`logging.pattern.file`|`FILE_LOG_PATTERN`|日志输出到文件时使用的模式(如果LOG_FILE启用,只支持默认的logback设置)|
-|`logging.pattern.level`|`LOG_LEVEL_PATTERN`|用来渲染日志级别的格式(默认`%5p`,只支持默认的logback设置)|
-|`PID`|`PID`|当前的处理进程(process)ID(能够找到,且还没有用作OS环境变量)|
-
-所有支持的日志系统在解析配置文件时都能获取系统属性的值,具体可以参考`spring-boot.jar`中的默认配置。
-
-**注** 如果想在日志属性中使用占位符,你需要使用[Spring Boot的语法](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-external-config-placeholders-in-properties),而不是底层框架的语法。尤其是使用Logback时,你需要使用`:`作为属性名和默认值的分隔符,而不是`:-`。
-
-**注** 通过覆盖`LOG_LEVEL_PATTERN`(Logback对应`logging.pattern.level`),你可以向日志中添加MDC和其他ad-hoc的内容。例如,将该值设置为`logging.pattern.level=user:%X{user} %5p`,则默认日志格式将包含一个"user"的MDC实体,如果存在的话,比如:
-```properties
-2015-09-30 12:30:04.031 user:juergen INFO 22174 --- [ nio-8080-exec-0] demo.Controller
-Handling authenticated request
-```
diff --git a/IV. Spring Boot features/26.6. Logback Extensions.md b/IV. Spring Boot features/26.6. Logback Extensions.md
new file mode 100644
index 00000000..bb2b1739
--- /dev/null
+++ b/IV. Spring Boot features/26.6. Logback Extensions.md
@@ -0,0 +1,12 @@
+### 26.6 Logback扩展
+
+Spring Boot包含很多有用的Logback扩展,你可以在`logback-spring.xml`配置文件中使用它们。
+
+**注** 你不能在标准的`logback.xml`配置文件中使用扩展,因为它加载的太早了,不过可以使用`logback-spring.xml`,或指定`logging.config`属性。
+
+**警告** 这些扩展不能和`Logback`的配置扫描一起使用。如果你尝试这样做,改变配置文件会导致类似与下面的错误:
+
+```properties
+ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
+ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
+```
diff --git a/IV. Spring Boot features/26.6. Logback extensions.md b/IV. Spring Boot features/26.6. Logback extensions.md
deleted file mode 100644
index 63ea38ec..00000000
--- a/IV. Spring Boot features/26.6. Logback extensions.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 26.6 Logback扩展
-Spring Boot包含很多有用的Logback扩展,你可以在`logback-spring.xml`配置文件中使用它们。
-
-**注** 你不能在标准的`logback.xml`配置文件中使用扩展,因为它加载的太早了,不过可以使用`logback-spring.xml`,或指定`logging.config`属性。
-
-**警告⚠️** 这些扩展不能和`Logback`的配置扫描一起使用。如果你尝试这样做,改变配置文件会导致类似与下面的错误:👇
-
-```properties
-ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
-ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
-```
\ No newline at end of file
diff --git a/IV. Spring Boot features/26.6.1. Profile-specific Configuration.md b/IV. Spring Boot features/26.6.1. Profile-specific Configuration.md
new file mode 100644
index 00000000..34f0edcf
--- /dev/null
+++ b/IV. Spring Boot features/26.6.1. Profile-specific Configuration.md
@@ -0,0 +1,16 @@
+### 26.6.1 Profile-specific配置
+
+``标签可用于根据激活的Spring profiles,选择性的包含或排除配置片段。Profile片段可以放在``元素内的任何地方,使用`name`属性定义哪些profile接受该配置,多个profiles以逗号分隔。下面展示了三个profile的示例:
+```xml
+
+
+
+
+
+
+
+
+
+
+
+```
diff --git a/IV. Spring Boot features/26.6.1. Profile-specific configuration.md b/IV. Spring Boot features/26.6.1. Profile-specific configuration.md
deleted file mode 100644
index 1476f9d0..00000000
--- a/IV. Spring Boot features/26.6.1. Profile-specific configuration.md
+++ /dev/null
@@ -1,15 +0,0 @@
-### 26.6.1 Profile-specific配置
-``标签可用于根据激活的Spring profiles,选择性的包含或排除配置片段。Profile片段可以放在``元素内的任何地方,使用`name`属性定义哪些profile接受该配置,多个profiles以逗号分隔。
-```xml
-
-
-
-
-
-
-
-
-
-
-
-```
diff --git a/IV. Spring Boot features/26.6.2. Environment Properties.md b/IV. Spring Boot features/26.6.2. Environment Properties.md
new file mode 100644
index 00000000..44a0b958
--- /dev/null
+++ b/IV. Spring Boot features/26.6.2. Environment Properties.md
@@ -0,0 +1,12 @@
+### 26.6.2 Environment属性
+
+``标签允许你从Spring `Environment`读取属性,以便在Logback中使用。如果你想在logback配置获取`application.properties`中的属性值,该功能就很有用。该标签工作方式跟Logback标准``标签类似,但不是直接指定`value`值,你需要定义属性的`source`(来自`Environment`),也可以指定存储属性作用域的`scope`。如果`Environment`没有相应属性,你可以通过`defaultValue`设置默认值。下面的例子展示了如何将属性暴露给Logback使用:
+```xml
+
+
+ ${fluentHost}
+ ...
+
+```
+**注** `source`必须使用短横线隔开(`my.property-name`)的格式指定。但是,属性可以通过relaxed规则添加到`Environment`里。
diff --git a/IV. Spring Boot features/26.6.2. Environment properties.md b/IV. Spring Boot features/26.6.2. Environment properties.md
deleted file mode 100644
index b4a3d67f..00000000
--- a/IV. Spring Boot features/26.6.2. Environment properties.md
+++ /dev/null
@@ -1,12 +0,0 @@
-### 26.6.2 Environment属性
-
-``标签允许你从Spring `Environment`读取属性,以便在Logback中使用。如果你想在logback配置获取`application.properties`中的属性值,该功能就很有用。该标签工作方式跟Logback标准``标签类似,但不是直接指定`value`值,你需要定义属性的`source`(来自`Environment`),也可以指定存储属性作用域的`scope`。如果`Environment`没有相应属性,你可以通过`defaultValue`设置默认值。
-```xml
-
-
- ${fluentHost}
- ...
-
-```
-**注** `source`必须使用短横线隔开(`my.property-name`)的格式指定。但是,属性可以通过relaxed规则添加到`Environment`里。
\ No newline at end of file
diff --git a/IV. Spring Boot features/27. Developing Web Applications.md b/IV. Spring Boot features/27. Developing Web Applications.md
new file mode 100644
index 00000000..9a576e04
--- /dev/null
+++ b/IV. Spring Boot features/27. Developing Web Applications.md
@@ -0,0 +1,5 @@
+### 27. 开发Web应用
+
+Spring Boot非常适合开发web应用程序。你可以使用内嵌的Tomcat,Jetty,Undertow或Netty创建一个HTTP服务器。大多数的web应用都可以使用`spring-boot-starter-web`模块进行快速搭建和运行。你也可以使用`spring-boot-starter-webflux`模块,来构建响应式的网络应用。
+
+如果没有开发过Spring Boot web应用,可以参考[Getting started章节](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#getting-started-first-application)的"Hello World!"示例。
diff --git a/IV. Spring Boot features/27. Developing web applications.md b/IV. Spring Boot features/27. Developing web applications.md
deleted file mode 100644
index 3a35886e..00000000
--- a/IV. Spring Boot features/27. Developing web applications.md
+++ /dev/null
@@ -1,4 +0,0 @@
-### 27. 开发Web应用
-Spring Boot非常适合开发web应用程序。你可以使用内嵌的Tomcat,Jetty,Undertow或Netty轻轻松松地创建一个HTTP服务器。大多数的web应用都可以使用`spring-boot-starter-web`模块进行快速搭建和运行。你也可以使用`spring-boot-starter-webflux`模块,来构建响应式的网络应用。
-
-如果没有开发过Spring Boot web应用,可以参考[Getting started章节](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#getting-started-first-application)的"Hello World!"示例。
diff --git "a/IV. Spring Boot features/27.1. The \342\200\230Spring Web MVC framework\342\200\231.md" "b/IV. Spring Boot features/27.1. The \342\200\230Spring Web MVC framework\342\200\231.md"
deleted file mode 100644
index 3ba19648..00000000
--- "a/IV. Spring Boot features/27.1. The \342\200\230Spring Web MVC framework\342\200\231.md"
+++ /dev/null
@@ -1,28 +0,0 @@
-### 27.1. Spring Web MVC框架
-
-Spring Web MVC框架(通常简称为"Spring MVC")是一个富“模型,视图,控制器”web框架,
-允许用户创建特定的`@Controller`或`@RestController` beans来处理传入的HTTP请求,通过`@RequestMapping`注解可以将控制器中的方法映射到相应的HTTP请求。
-
-示例:
-```java
-@RestController
-@RequestMapping(value="/users")
-public class MyRestController {
-
- @RequestMapping(value="/{user}", method=RequestMethod.GET)
- public User getUser(@PathVariable Long user) {
- // ...
- }
-
- @RequestMapping(value="/{user}/customers", method=RequestMethod.GET)
- List getUserCustomers(@PathVariable Long user) {
- // ...
- }
-
- @RequestMapping(value="/{user}", method=RequestMethod.DELETE)
- public User deleteUser(@PathVariable Long user) {
- // ...
- }
-}
-```
-Spring MVC是Spring框架的核心部分,详细信息可以参考[reference documentation](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle#mvc),[spring.io/guides](http://spring.io/guides)也有一些可用的指导覆盖Spring MVC。
diff --git "a/IV. Spring Boot features/27.1. The \342\200\234Spring Web MVC Framework\342\200\235.md" "b/IV. Spring Boot features/27.1. The \342\200\234Spring Web MVC Framework\342\200\235.md"
new file mode 100644
index 00000000..cf883845
--- /dev/null
+++ "b/IV. Spring Boot features/27.1. The \342\200\234Spring Web MVC Framework\342\200\235.md"
@@ -0,0 +1,28 @@
+### 27.1. Spring Web MVC框架
+
+Spring Web MVC框架(通常简称为"Spring MVC")是一个富“模型,视图,控制器”web框架,
+允许用户创建特定的`@Controller`或`@RestController` beans来处理传入的HTTP请求,通过`@RequestMapping`注解可以将控制器中的方法映射到相应的HTTP请求。
+
+示例:
+```java
+@RestController
+@RequestMapping(value="/users")
+public class MyRestController {
+
+ @RequestMapping(value="/{user}", method=RequestMethod.GET)
+ public User getUser(@PathVariable Long user) {
+ // ...
+ }
+
+ @RequestMapping(value="/{user}/customers", method=RequestMethod.GET)
+ List getUserCustomers(@PathVariable Long user) {
+ // ...
+ }
+
+ @RequestMapping(value="/{user}", method=RequestMethod.DELETE)
+ public User deleteUser(@PathVariable Long user) {
+ // ...
+ }
+}
+```
+Spring MVC是Spring框架的核心部分,详细信息可以参考[reference documentation](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/htmlsingle#mvc),[spring.io/guides](http://spring.io/guides)也有一些可用的指导覆盖Spring MVC。
diff --git a/IV. Spring Boot features/27.1.1. Spring MVC Auto-configuration.md b/IV. Spring Boot features/27.1.1. Spring MVC Auto-configuration.md
new file mode 100644
index 00000000..ef7d1b8b
--- /dev/null
+++ b/IV. Spring Boot features/27.1.1. Spring MVC Auto-configuration.md
@@ -0,0 +1,16 @@
+### 27.1.1. Spring MVC自动配置
+
+Spring Boot为Spring MVC提供的auto-configuration适用于大多数应用,并在Spring默认功能上添加了以下特性:
+
+1. 引入`ContentNegotiatingViewResolver`和`BeanNameViewResolver` beans。
+2. 对静态资源的支持,包括对WebJars的支持。
+3. 自动注册`Converter`,`GenericConverter`,`Formatter` beans。
+4. 对`HttpMessageConverters`的支持。
+5. 自动注册`MessageCodeResolver`。
+6. 对静态`index.html`的支持。
+7. 对自定义`Favicon`的支持。
+8. 自动使用`ConfigurableWebBindingInitializer` bean。
+
+如果保留Spring Boot MVC特性,你只需添加其他的[MVC配置](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#mvc)(拦截器,格式化处理器,视图控制器等)。你可以添加自己的`WebMvcConfigurer`类型的`@Configuration`类,而不需要注解`@EnableWebMvc`。如果希望使用自定义的`RequestMappingHandlerMapping`,`RequestMappingHandlerAdapter`,或`ExceptionHandlerExceptionResolver`,你可以声明一个`WebMvcRegistrationsAdapter`实例提供这些组件。
+
+如果想全面控制Spring MVC,你可以添加自己的`@Configuration`,并使用`@EnableWebMvc`注解。
diff --git a/IV. Spring Boot features/27.1.1. Spring MVC auto-configuration.md b/IV. Spring Boot features/27.1.1. Spring MVC auto-configuration.md
deleted file mode 100644
index cdb2c8d5..00000000
--- a/IV. Spring Boot features/27.1.1. Spring MVC auto-configuration.md
+++ /dev/null
@@ -1,17 +0,0 @@
-### 27.1.1. Spring MVC自动配置
-
-Spring Boot为Spring MVC提供的auto-configuration适用于大多数应用,并在Spring默认功能上添加了以下特性:
-
-1. 引入`ContentNegotiatingViewResolver`和`BeanNameViewResolver` beans。
-2. 对静态资源的支持,包括对WebJars的支持。
-3. 自动注册`Converter`,`GenericConverter`,`Formatter` beans。
-4. 对`HttpMessageConverters`的支持。
-5. 自动注册`MessageCodeResolver`。
-6. 对静态`index.html`的支持。
-7. 对自定义`Favicon`的支持。
-8. 自动使用`ConfigurableWebBindingInitializer` bean。
-
-如果保留Spring Boot MVC特性,你只需添加其他的[MVC配置](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/web.html#mvc)(拦截器,格式化处理器,视图控制器等)。你可以添加自己的`WebMvcConfigurer`类型的`@Configuration`类,而不需要注解`@EnableWebMvc`。如果希望使用自定义的`RequestMappingHandlerMapping`,`RequestMappingHandlerAdapter`,或`ExceptionHandlerExceptionResolver`,你可以声明一个`WebMvcRegistrationsAdapter`实例提供这些组件。
-
-
-如果想全面控制Spring MVC,你可以添加自己的`@Configuration`,并使用`@EnableWebMvc`注解。
diff --git a/IV. Spring Boot features/27.1.10. Spring HATEOAS.md b/IV. Spring Boot features/27.1.10. Spring HATEOAS.md
deleted file mode 100644
index b190bef8..00000000
--- a/IV. Spring Boot features/27.1.10. Spring HATEOAS.md
+++ /dev/null
@@ -1,6 +0,0 @@
-### 27.1.10 Spring HATEOAS
-
-如果正在开发基于超媒体的RESTful API,你可能需要Spring HATEOAS,而Spring Boot会为其提供自动配置,这在大多数应用中都运作良好。
-自动配置取代了`@EnableHypermediaSupport`,只需注册一定数量的beans就能轻松构建基于超媒体的应用,这些beans包括`LinkDiscoverers`(客户端支持),`ObjectMapper`(用于将响应编排为想要的形式)。`ObjectMapper`可以根据`spring.jackson.*`属性或`Jackson2ObjectMapperBuilder` bean进行自定义。
-
-通过注解`@EnableHypermediaSupport`,你可以控制Spring HATEOAS的配置,但这会禁用上述`ObjectMapper`的自定义功能。
diff --git a/IV. Spring Boot features/27.1.10. Template Engines.md b/IV. Spring Boot features/27.1.10. Template Engines.md
new file mode 100644
index 00000000..c3c4c113
--- /dev/null
+++ b/IV. Spring Boot features/27.1.10. Template Engines.md
@@ -0,0 +1,16 @@
+### 27.1.10 模板引擎
+
+正如REST web服务,你也可以使用Spring MVC提供动态HTML内容。Spring MVC支持各种各样的模板技术,包括Thymeleaf, FreeMarker和JSPs,很多其他的模板引擎也提供它们自己的Spring MVC集成。
+
+Spring Boot为以下的模板引擎提供自动配置支持:
+
+* [FreeMarker](http://freemarker.org/docs/)
+* [Groovy](http://beta.groovy-lang.org/docs/groovy-2.3.0/html/documentation/markup-template-engine.html)
+* [Thymeleaf](http://www.thymeleaf.org/)
+* [Mustache](http://mustache.github.io/)
+
+**注**:由于在内嵌servlet容器中使用JSPs存在一些[已知的限制](27.4.5. JSP limitations.md),所以建议尽量不使用它们。
+
+使用以上引擎中的任何一种,并采用默认配置,则模块会从`src/main/resources/templates`自动加载。
+
+**注**:IntelliJ IDEA根据你运行应用的方式会对classpath进行不同的排序。在IDE里通过main方法运行应用,跟从Maven,或Gradle,或打包好的jar中运行相比会导致不同的顺序,这可能导致Spring Boot不能从classpath下成功地找到模板。如果遇到这个问题,你可以在IDE里重新对classpath进行排序,将模块的类和资源放到第一位。或者,你可以配置模块的前缀为`classpath*:/templates/`,这样会查找classpath下的所有模板目录。
diff --git a/IV. Spring Boot features/27.1.11. CORS support.md b/IV. Spring Boot features/27.1.11. CORS support.md
deleted file mode 100644
index d4cfe3bc..00000000
--- a/IV. Spring Boot features/27.1.11. CORS support.md
+++ /dev/null
@@ -1,20 +0,0 @@
-### 27.1.11 CORS支持
-
-[跨域资源共享](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)(CORS)是一个[大多数浏览器](http://caniuse.com/#feat=cors)都实现了的[W3C标准](http://www.w3.org/TR/cors/),它允许你以灵活的方式指定跨域请求如何被授权,而不是采用那些不安全,性能低的方式,比如IFRAME或JSONP。
-
-从4.2版本开始,Spring MVC对[CORS](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#cors)提供开箱即用的支持。不用添加任何特殊配置,只需要在Spring Boot应用的controller方法上注解[`@CrossOrigin`](https://docs.spring.io/spring/docs/5.0.0.RELEASE/javadoc-api/org/springframework/web/bind/annotation/CrossOrigin.html),并添加[CORS配置](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#_controller_method_cors_configuration)。通过注册一个自定义`addCorsMappings(CorsRegistry)`方法的`WebMvcConfigurer` bean可以指定[全局CORS配置](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#_global_cors_configuration):
-```java
-@Configuration
-public class MyConfiguration {
-
- @Bean
- public WebMvcConfigurer corsConfigurer() {
- return new WebMvcConfigurer() {
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/api/**");
- }
- };
- }
-}
-```
diff --git a/IV. Spring Boot features/27.1.11. Error Handling.md b/IV. Spring Boot features/27.1.11. Error Handling.md
new file mode 100644
index 00000000..6e510d6a
--- /dev/null
+++ b/IV. Spring Boot features/27.1.11. Error Handling.md
@@ -0,0 +1,108 @@
+### 27.1.11 错误处理
+
+Spring Boot默认提供一个`/error`映射用来以合适的方式处理所有的错误,并将它注册为servlet容器中全局的
+错误页面。对于机器客户端(相对于浏览器而言,浏览器偏重于人的行为),它会产生一个具有详细错误,HTTP状态,异常信息的JSON响应。对于浏览器客户端,它会产生一个白色标签样式(whitelabel)的错误视图,该视图将以HTML格式显示同样的数据(可以添加一个解析为'error'的View来自定义它)。为了完全替换默认的行为,你可以实现`ErrorController`,并注册一个该类型的bean定义,或简单地添加一个`ErrorAttributes`类型的bean以使用现存的机制,只是替换显示的内容。
+
+**注** `BasicErrorController`可以作为自定义`ErrorController`的基类,如果你想添加对新context type的处理(默认处理`text/html`),这会很有帮助。你只需要继承`BasicErrorController`,添加一个public方法,并注解带有`produces`属性的`@RequestMapping`,然后创建该新类型的bean。
+
+你也可以定义一个注解为`@ControllerAdvice`的类去自定义某个特殊controller或exception类型的JSON文档。如下所示:
+```java
+@ControllerAdvice(basePackageClasses = AcmeController.class)
+public class AcmeControllerAdvice extends ResponseEntityExceptionHandler {
+
+ @ExceptionHandler(YourException.class)
+ @ResponseBody
+ ResponseEntity> handleControllerException(HttpServletRequest request, Throwable ex) {
+ HttpStatus status = getStatus(request);
+ return new ResponseEntity<>(new CustomErrorType(status.value(), ex.getMessage()), status);
+ }
+
+ private HttpStatus getStatus(HttpServletRequest request) {
+ Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
+ if (statusCode == null) {
+ return HttpStatus.INTERNAL_SERVER_ERROR;
+ }
+ return HttpStatus.valueOf(statusCode);
+ }
+
+}
+```
+在以上示例中,如果跟`AcmeController`相同package的某个controller抛出`YourException`,一个`CustomErrorType`类型的POJO的JSON展示将代替`ErrorAttributes`展示。
+
+**自定义错误页面**
+
+如果想为某个给定的状态码展示一个自定义的HTML错误页面,你需要将文件添加到`/error`文件夹下。错误页面既可以是静态HTML(比如,任何静态资源文件夹下添加的),也可以是使用模板构建的,文件名必须是明确的状态码或一系列标签。
+
+例如,映射`404`到一个静态HTML文件,你的目录结构可能如下:
+```properties
+src/
+ +- main/
+ +- java/
+ | +
+ +- resources/
+ +- public/
+ +- error/
+ | +- 404.html
+ +-
+```
+使用FreeMarker模板映射所有`5xx`错误,你需要如下的目录结构:
+```properties
+src/
+ +- main/
+ +- java/
+ | +
+ +- resources/
+ +- templates/
+ +- error/
+ | +- 5xx.ftl
+ +-
+```
+对于更复杂的映射,你可以添加实现`ErrorViewResolver`接口的beans:
+```java
+public class MyErrorViewResolver implements ErrorViewResolver {
+
+ @Override
+ public ModelAndView resolveErrorView(HttpServletRequest request,
+ HttpStatus status, Map model) {
+ // Use the request or status to optionally return a ModelAndView
+ return ...
+ }
+
+}
+```
+你也可以使用Spring MVC特性,比如[@ExceptionHandler方法](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/htmlsingle/#mvc-exceptionhandlers)和[@ControllerAdvice](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice),`ErrorController`将处理所有未处理的异常。
+
+**映射Spring MVC以外的错误页面**
+
+对于不使用Spring MVC的应用,你可以通过`ErrorPageRegistrar`接口直接注册`ErrorPages`。该抽象直接工作于底层内嵌servlet容器,即使你没有Spring MVC的`DispatcherServlet`,它们仍旧可以工作。
+```java
+@Bean
+public ErrorPageRegistrar errorPageRegistrar(){
+ return new MyErrorPageRegistrar();
+}
+
+// ...
+
+private static class MyErrorPageRegistrar implements ErrorPageRegistrar {
+
+ @Override
+ public void registerErrorPages(ErrorPageRegistry registry) {
+ registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
+ }
+
+}
+```
+**注** 如果你注册一个`ErrorPage`,该页面需要被一个`Filter`处理(在一些非Spring web框架中很常见,比如Jersey,Wicket),那么该`Filter`需要明确注册为一个`ERROR`分发器(dispatcher),例如:
+```java
+@Bean
+public FilterRegistrationBean myFilter() {
+ FilterRegistrationBean registration = new FilterRegistrationBean();
+ registration.setFilter(new MyFilter());
+ ...
+ registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
+ return registration;
+}
+```
+默认的`FilterRegistrationBean`不包含`ERROR` dispatcher类型。
+
+注意:当部署到一个servlet容器时,Spring Boot通过它的错误页面过滤器将带有错误状态的请求转发到恰当的错误页面。request只有在response还没提交时才能转发(forwarded)到正确的错误页面,而WebSphere应用服务器8.0及后续版本默认情况会在servlet方法成功执行后提交response,你需要设置`com.ibm.ws.webcontainer.invokeFlushAfterService`属性为`false`来关闭该行为。
diff --git a/IV. Spring Boot features/27.1.12. Spring HATEOAS.md b/IV. Spring Boot features/27.1.12. Spring HATEOAS.md
new file mode 100644
index 00000000..c4cd6613
--- /dev/null
+++ b/IV. Spring Boot features/27.1.12. Spring HATEOAS.md
@@ -0,0 +1,6 @@
+### 27.1.12 Spring HATEOAS
+
+如果正在开发基于超媒体的RESTful API,你可能需要Spring HATEOAS,而Spring Boot会为其提供自动配置,这在大多数应用中都运作良好。
+自动配置取代了`@EnableHypermediaSupport`,只需注册一定数量的beans就能轻松构建基于超媒体的应用,这些beans包括`LinkDiscoverers`(客户端支持),`ObjectMapper`(用于将响应编排为想要的形式)。`ObjectMapper`可以根据`spring.jackson.*`属性或`Jackson2ObjectMapperBuilder` bean进行自定义。
+
+通过注解`@EnableHypermediaSupport`,你可以控制Spring HATEOAS的配置,但这会禁用上述`ObjectMapper`的自定义功能。
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.1.13. CORS support.md b/IV. Spring Boot features/27.1.13. CORS support.md
new file mode 100644
index 00000000..f4f2e2f6
--- /dev/null
+++ b/IV. Spring Boot features/27.1.13. CORS support.md
@@ -0,0 +1,20 @@
+### 27.1.13 CORS支持
+
+[跨域资源共享](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)(CORS)是一个[大多数浏览器](https://caniuse.com/#feat=cors)都实现了的[W3C标准](https://www.w3.org/TR/cors/),它允许你以灵活的方式指定跨域请求如何被授权,而不是采用那些不安全,性能低的方式,比如IFRAME或JSONP。
+
+从4.2版本开始,Spring MVC对[CORS](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#cors)提供开箱即用的支持。不用添加任何特殊配置,只需要在Spring Boot应用的controller方法上注解[`@CrossOrigin`](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/web/bind/annotation/CrossOrigin.html),并添加[CORS配置](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#controller-method-cors-configuration)。通过注册一个自定义`addCorsMappings(CorsRegistry)`方法的`WebMvcConfigurer` bean可以指定[全局CORS配置](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#global-cors-configuration):
+```java
+@Configuration
+public class MyConfiguration {
+
+ @Bean
+ public WebMvcConfigurer corsConfigurer() {
+ return new WebMvcConfigurer() {
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/api/**");
+ }
+ };
+ }
+}
+```
diff --git a/IV. Spring Boot features/27.1.2. HttpMessageConverters.md b/IV. Spring Boot features/27.1.2. HttpMessageConverters.md
index 478ab543..947ac089 100644
--- a/IV. Spring Boot features/27.1.2. HttpMessageConverters.md
+++ b/IV. Spring Boot features/27.1.2. HttpMessageConverters.md
@@ -1,8 +1,8 @@
### 27.1.2. HttpMessageConverters
-Spring MVC使用`HttpMessageConverter`接口转换HTTP请求和响应,合适的默认配置可以开箱即用,例如对象自动转换为JSON(使用Jackson库)或XML(如果Jackson XML扩展可用,否则使用JAXB),字符串默认使用`UTF-8`编码。
+Spring MVC使用`HttpMessageConverter`接口转换HTTP请求和响应。合适的默认配置可以开箱即用,例如对象自动转换为JSON(使用Jackson库)或XML(如果Jackson XML扩展可用,否则使用JAXB),字符串默认使用`UTF-8`编码。
-可以使用Spring Boot的`HttpMessageConverters`类添加或自定义转换类:
+可以使用Spring Boot的`HttpMessageConverters`类添加或自定义转换类,如下所示:
```java
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.*;
@@ -19,4 +19,4 @@ public class MyConfiguration {
}
}
```
-上下文中出现的所有`HttpMessageConverter` bean都将添加到converters列表,你可以通过这种方式覆盖默认的转换器列表(converters)。
+上下文中出现的所有`HttpMessageConverter` bean都将添加到converters列表。你可以通过这种方式覆盖默认的转换器列表(converters)。
diff --git a/IV. Spring Boot features/27.1.3. Custom JSON Serializers and Deserializers.md b/IV. Spring Boot features/27.1.3. Custom JSON Serializers and Deserializers.md
index 3f2bab43..54a7fa7a 100644
--- a/IV. Spring Boot features/27.1.3. Custom JSON Serializers and Deserializers.md
+++ b/IV. Spring Boot features/27.1.3. Custom JSON Serializers and Deserializers.md
@@ -1,3 +1,29 @@
-###27.1.3 自定义JSON序列化器和反序列化器
+### 27.1.3 自定义JSON序列化器和反序列化器
如果使用Jackson序列化,反序列化JSON数据,你可能想编写自己的`JsonSerializer`和`JsonDeserializer`类。自定义序列化器(serializers)通常[通过Module注册到Jackson](http://wiki.fasterxml.com/JacksonHowToCustomDeserializers),但Spring Boot提供了`@JsonComponent`注解这一替代方式,它能轻松的将序列化器注册为Spring Beans。
+
+你可以在`JsonSerializer`或者`JsonDeserializer`的实现上,直接使用`@JsonComponent`注解。你也可以在以内部类的形式包含序列化器/反序列化器的类上使用它,如下所示:
+
+```
+import java.io.*;
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.databind.*;
+import org.springframework.boot.jackson.*;
+
+@JsonComponent
+public class Example {
+
+ public static class Serializer extends JsonSerializer {
+ // ...
+ }
+
+ public static class Deserializer extends JsonDeserializer {
+ // ...
+ }
+
+}
+```
+
+`ApplicationContext`里所有的`@JsonComponent` bean会自动注册到Jackson。因为`@JsonComponent`用`@Component`进行元注解,会应用通常的组件扫描规则。
+
+Spring Boot也提供了[`JsonObjectSerializer`](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jackson/JsonObjectSerializer.java)和[`JsonObjectDeserializer`](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jackson/JsonObjectDeserializer.java)基础类。它们为标准的Jackson版本提供了替代选择。详情请查看[`JsonObjectSerializer`](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/jackson/JsonObjectSerializer.html)和[`JsonObjectDeserializer`](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/jackson/JsonObjectDeserializer.html)的Javadoc。
diff --git a/IV. Spring Boot features/27.1.4. MessageCodesResolver.md b/IV. Spring Boot features/27.1.4. MessageCodesResolver.md
index c657cd2d..c5fce621 100644
--- a/IV. Spring Boot features/27.1.4. MessageCodesResolver.md
+++ b/IV. Spring Boot features/27.1.4. MessageCodesResolver.md
@@ -1,3 +1,3 @@
### 27.1.4 MessageCodesResolver
-Spring MVC有一个实现策略,用于从绑定的errors产生用来渲染错误信息的错误码:`MessageCodesResolver`。Spring Boot会自动为你创建该实现,只要设置`spring.mvc.message-codes-resolver.format`属性为`PREFIX_ERROR_CODE`或`POSTFIX_ERROR_CODE`(具体查看`DefaultMessageCodesResolver.Format`枚举值)。
+Spring MVC有一个实现策略,用于从绑定的errors产生用来渲染错误信息的错误码:`MessageCodesResolver`。只要设置`spring.mvc.message-codes-resolver.format`属性为`PREFIX_ERROR_CODE`或`POSTFIX_ERROR_CODE`,Spring Boot会自动为你创建该实现(具体查看`DefaultMessageCodesResolver.Format`枚举值)。
diff --git a/IV. Spring Boot features/27.1.5. Static Content.md b/IV. Spring Boot features/27.1.5. Static Content.md
index 2867a648..5c166ba4 100644
--- a/IV. Spring Boot features/27.1.5. Static Content.md
+++ b/IV. Spring Boot features/27.1.5. Static Content.md
@@ -4,11 +4,11 @@
在单机web应用中,容器会启动默认的servlet,并用它加载`ServletContext`根目录下的内容以响应那些Spring不处理的请求。大多数情况下这都不会发生(除非你修改默认的MVC配置),因为Spring总能够通过`DispatcherServlet`处理这些请求。
-默认地,资源放置在`/**`,但是你可以通过`spring.mvc.static-path-pattern`进行调整。例如,迁移所有的资源到`/resources/**`可以按照如下方式实现:
+默认地,资源放置在`/**`,但是你可以通过`spring.mvc.static-path-pattern`属性进行调整。例如,迁移所有的资源到`/resources/**`可以按照如下方式实现:
```properties
spring.mvc.static-path-pattern=/resources/**
```
-你可以设置`spring.resources.static-locations`属性自定义静态资源的位置(配置一系列目录位置代替默认的值)。根Servlet的上下文路径“/”也会被作为一个位置自动添加。如果你这样做,默认的欢迎页面将从自定义位置加载,所以只要这些路径中的任何地方有一个`index.html`,它都会成为应用的主页。
+你可以设置`spring.resources.static-locations`属性自定义静态资源的位置(配置一系列目录位置代替默认的值)。根Servlet的上下文路径“/”也会被作为一个位置自动添加。
此外,除了上述标准的静态资源位置,有个例外情况是[Webjars内容](http://www.webjars.org/)。任何在`/webjars/**`路径下的资源都将从jar文件中提供,只要它们以Webjars的格式打包。
@@ -18,14 +18,14 @@ Spring Boot也支持Spring MVC提供的高级资源处理特性,可用于清
如果想使用针对WebJars版本无感知的URLs(version agnostic),只需要添加`webjars-locator`依赖,然后声明你的Webjar。以jQuery为例,`"/webjars/jquery/dist/jquery.min.js"`实际为`"/webjars/jquery/x.y.z/dist/jquery.min.js"`,`x.y.z`为Webjar的版本。
-**注** 如果使用JBoss,你需要声明`webjars-locator-jboss-vfs`依赖而不是`webjars-locator`,否则所有的Webjars将解析为`404`。
+**注** 如果使用JBoss,你需要声明`webjars-locator-jboss-vfs`依赖而不是`webjars-locator-core`,否则所有的Webjars将解析为`404`。
以下的配置为所有的静态资源提供一种缓存清除(cache busting)方案,实际上是将内容hash添加到URLs中,比如``:
```properties
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
```
-**注** 实现该功能的是`ResourceUrlEncodingFilter`,它在模板运行期会重写资源链接,Thymeleaf和FreeMarker会自动配置该filter,JSP需要手动配置。其他模板引擎还没自动支持,不过你可以使用[ResourceUrlProvider](https://docs.spring.io/spring/docs/5.0.0.RELEASE/javadoc-api/org/springframework/web/servlet/resource/ResourceUrlProvider.html)自定义模块宏或帮助类。
+**注** 实现该功能的是`ResourceUrlEncodingFilter`,它在模板运行期会重写资源链接,Thymeleaf和FreeMarker会自动配置该filter,JSP需要手动配置。其他模板引擎还没自动支持,不过你可以使用[ResourceUrlProvider](https://docs.spring.io/spring/docs/5.0.4.RELEASE/javadoc-api/org/springframework/web/servlet/resource/ResourceUrlProvider.html)自定义模块宏或帮助类。
当使用比如JavaScript模块加载器动态加载资源时,重命名文件是不行的,这也是提供其他策略并能结合使用的原因。下面是一个"fixed"策略,在URL中添加一个静态version字符串而不需要改变文件名:
```properties
@@ -35,6 +35,6 @@ spring.resources.chain.strategy.fixed.enabled=true
spring.resources.chain.strategy.fixed.paths=/js/lib/
spring.resources.chain.strategy.fixed.version=v12
```
-使用以上策略,JavaScript模块加载器加载`"/js/lib/"`下的文件时会使用一个固定的版本策略`"/v12/js/lib/mymodule.js"`,其他资源仍旧使用内容hash的方式``。查看[ResourceProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java)获取更多支持的选项。
+使用以上策略,JavaScript模块加载器加载`"/js/lib/"`下的文件时会使用一个固定的版本策略(`"/v12/js/lib/mymodule.js"`),其他资源仍旧使用内容hash的方式(``)。查看[ResourceProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java)获取更多支持的选项。
-**注** 该特性在一个专门的[博文](https://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources)和Spring框架[参考文档](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#mvc-config-static-resources)中有透彻描述。
+**注** 该特性在一个专门的[博文](https://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources)和Spring框架[参考文档](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/htmlsingle/#mvc-config-static-resources)中有透彻描述。
diff --git a/IV. Spring Boot features/27.1.6. Custom Favicon.md b/IV. Spring Boot features/27.1.6. Custom Favicon.md
deleted file mode 100644
index a33dc90d..00000000
--- a/IV. Spring Boot features/27.1.6. Custom Favicon.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 27.1.6 定制网站图标
-Spring Boot会在已配置的静态内容位置和类路径的根目录下依次寻找`favicon.ico`文件。 如果文件存在,它会被自动用作应用的图标。
-
diff --git a/IV. Spring Boot features/27.1.6. Welcome Page.md b/IV. Spring Boot features/27.1.6. Welcome Page.md
new file mode 100644
index 00000000..4bbb1774
--- /dev/null
+++ b/IV. Spring Boot features/27.1.6. Welcome Page.md
@@ -0,0 +1,3 @@
+### 27.1.6 欢迎页
+
+Spring Boot支持静态的和模板化的欢迎页。它首先会去配置好的静态内容位置寻找`index.html`文件。如果没找到,则会去寻找 `index`模版。如果找到其中之一,Spring Boot会自动把它当做应用的欢迎页。
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.1.7. ConfigurableWebBindingInitializer.md b/IV. Spring Boot features/27.1.7. ConfigurableWebBindingInitializer.md
deleted file mode 100644
index 8ce28c19..00000000
--- a/IV. Spring Boot features/27.1.7. ConfigurableWebBindingInitializer.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 27.1.7 ConfigurableWebBindingInitializer
-Spring MVC使用`WebBindingInitializer`为每个特殊的请求初始化相应的`WebDataBinder`,如果你创建自己的`ConfigurableWebBindingInitializer @Bean`,Spring Boot会自动配置Spring MVC使用它。
-
diff --git a/IV. Spring Boot features/27.1.7. Custom Favicon.md b/IV. Spring Boot features/27.1.7. Custom Favicon.md
new file mode 100644
index 00000000..263939be
--- /dev/null
+++ b/IV. Spring Boot features/27.1.7. Custom Favicon.md
@@ -0,0 +1,3 @@
+### 27.1.7 定制网站图标
+
+Spring Boot会在已配置的静态内容位置和类路径的根目录下依次寻找`favicon.ico`文件。 如果文件存在,它会被自动用作应用的图标。
diff --git a/IV. Spring Boot features/27.1.8. Path Matching and Content Negotiation.md b/IV. Spring Boot features/27.1.8. Path Matching and Content Negotiation.md
new file mode 100644
index 00000000..fa24f0b1
--- /dev/null
+++ b/IV. Spring Boot features/27.1.8. Path Matching and Content Negotiation.md
@@ -0,0 +1,29 @@
+### 27.1.8 路径匹配与内容协商
+
+Spring MVC能够查看请求路径,将HTTP请求映射到处理程序,并把它匹配到应用里定义的映射关系(比如,Controller方法的`@GetMapping`注解)。
+
+Spring Boot默认禁用后缀模式匹配。这意味着类似`"GET /projects/spring-boot.json"`的请求,不会匹配到`@GetMapping("/projects/spring-boot")`。这是[Spring MVC应用的一种最佳实践](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#mvc-ann-requestmapping-suffix-pattern-match)。过去,这个特性主要对HTTP客户端有用。HTTP客户端没有发送适当的"Accept"请求头。我们需要确保给客户端发送了正确的内容类型。现在,内容协商更为可靠。
+
+还有其它方式处理HTTP客户端没有发送适当的"Accept"请求头的情况。不使用后缀匹配,但我们可以使用一个查询参数,来确保类似于`"GET /projects/spring-boot?format=json"`的请求会映射到`@GetMapping("/projects/spring-boot")`:
+
+```properties
+spring.mvc.contentnegotiation.favor-parameter=true
+
+# We can change the parameter name, which is "format" by default:
+# spring.mvc.contentnegotiation.parameter-name=myparam
+
+# We can also register additional file extensions/media types with:
+spring.mvc.contentnegotiation.media-types.markdown=text/markdown
+```
+
+如果你理解上面的警告,但还是想要在你的应用里使用后缀模式匹配,你需要下面的配置:
+
+```properties
+spring.mvc.contentnegotiation.favor-path-extension=true
+
+# You can also restrict that feature to known extensions only
+# spring.mvc.pathmatch.use-registered-suffix-pattern=true
+
+# We can also register additional file extensions/media types with:
+# spring.mvc.contentnegotiation.media-types.adoc=text/asciidoc
+```
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.1.8. Template engines.md b/IV. Spring Boot features/27.1.8. Template engines.md
deleted file mode 100644
index 73685de8..00000000
--- a/IV. Spring Boot features/27.1.8. Template engines.md
+++ /dev/null
@@ -1,16 +0,0 @@
-### 27.1.8 模板引擎
-
-正如REST web服务,你也可以使用Spring MVC提供动态HTML内容。Spring MVC支持各种各样的模板技术,包括Thymeleaf, FreeMarker和JSPs,很多其他的模板引擎也提供它们自己的Spring MVC集成。
-
-Spring Boot为以下的模板引擎提供自动配置支持:
-
-* [FreeMarker](http://freemarker.org/docs/)
-* [Groovy](http://beta.groovy-lang.org/docs/groovy-2.3.0/html/documentation/markup-template-engine.html)
-* [Thymeleaf](http://www.thymeleaf.org/)
-* [Mustache](http://mustache.github.io/)
-
-**注**:由于在内嵌servlet容器中使用JSPs存在一些[已知的限制](27.3.5. JSP limitations.md),所以建议尽量不使用它们。
-
-使用以上引擎中的任何一种,并采用默认配置,则模块会从`src/main/resources/templates`自动加载。
-
-**注**:IntelliJ IDEA根据你运行应用的方式会对classpath进行不同的排序。在IDE里通过main方法运行应用,跟从Maven,或Gradle,或打包好的jar中运行相比会导致不同的顺序,这可能导致Spring Boot不能从classpath下成功地找到模板。如果遇到这个问题,你可以在IDE里重新对classpath进行排序,将模块的类和资源放到第一位。或者,你可以配置模块的前缀为`classpath*:/templates/`,这样会查找classpath下的所有模板目录。
diff --git a/IV. Spring Boot features/27.1.9. ConfigurableWebBindingInitializer.md b/IV. Spring Boot features/27.1.9. ConfigurableWebBindingInitializer.md
new file mode 100644
index 00000000..2a78d01f
--- /dev/null
+++ b/IV. Spring Boot features/27.1.9. ConfigurableWebBindingInitializer.md
@@ -0,0 +1,3 @@
+### 27.1.9 ConfigurableWebBindingInitializer
+
+Spring MVC使用`WebBindingInitializer`为每个特殊的请求初始化相应的`WebDataBinder`,如果你创建自己的`ConfigurableWebBindingInitializer @Bean`,Spring Boot会自动配置Spring MVC使用它。
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.1.9. Error Handling.md b/IV. Spring Boot features/27.1.9. Error Handling.md
deleted file mode 100644
index 8bd635c5..00000000
--- a/IV. Spring Boot features/27.1.9. Error Handling.md
+++ /dev/null
@@ -1,110 +0,0 @@
-### 27.1.9 错误处理
-
-Spring Boot默认提供一个`/error`映射用来以合适的方式处理所有的错误,并将它注册为servlet容器中全局的
-错误页面。对于机器客户端(相对于浏览器而言,浏览器偏重于人的行为),它会产生一个具有详细错误,HTTP状态,异常信息的JSON响应。对于浏览器客户端,它会产生一个白色标签样式(whitelabel)的错误视图,该视图将以HTML格式显示同样的数据(可以添加一个解析为'error'的View来自定义它)。为了完全替换默认的行为,你可以实现`ErrorController`,并注册一个该类型的bean定义,或简单地添加一个`ErrorAttributes`类型的bean以使用现存的机制,只是替换显示的内容。
-
-**注** `BasicErrorController`可以作为自定义`ErrorController`的基类,如果你想添加对新context type的处理(默认处理`text/html`),这会很有帮助。你只需要继承`BasicErrorController`,添加一个public方法,并注解带有`produces`属性的`@RequestMapping`,然后创建该新类型的bean。
-
-你也可以定义一个`@ControllerAdvice`去自定义某个特殊controller或exception类型的JSON文档:
-```java
-@ControllerAdvice(basePackageClasses = FooController.class)
-public class FooControllerAdvice extends ResponseEntityExceptionHandler {
-
- @ExceptionHandler(YourException.class)
- @ResponseBody
- ResponseEntity> handleControllerException(HttpServletRequest request, Throwable ex) {
- HttpStatus status = getStatus(request);
- return new ResponseEntity<>(new CustomErrorType(status.value(), ex.getMessage()), status);
- }
-
- private HttpStatus getStatus(HttpServletRequest request) {
- Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
- if (statusCode == null) {
- return HttpStatus.INTERNAL_SERVER_ERROR;
- }
- return HttpStatus.valueOf(statusCode);
- }
-
-}
-```
-在以上示例中,如果跟`FooController`相同package的某个controller抛出`YourException`,一个`CustomerErrorType`类型的POJO的json展示将代替`ErrorAttributes`展示。
-
-**自定义错误页面**
-
-如果想为某个给定的状态码展示一个自定义的HTML错误页面,你需要将文件添加到`/error`文件夹下。错误页面既可以是静态HTML(比如,任何静态资源文件夹下添加的),也可以是使用模板构建的,文件名必须是明确的状态码或一系列标签。
-
-例如,映射`404`到一个静态HTML文件,你的目录结构可能如下:
-```properties
-src/
- +- main/
- +- java/
- | +
- +- resources/
- +- public/
- +- error/
- | +- 404.html
- +-
-```
-使用FreeMarker模板映射所有`5xx`错误,你需要如下的目录结构:
-```properties
-src/
- +- main/
- +- java/
- | +
- +- resources/
- +- templates/
- +- error/
- | +- 5xx.ftl
- +-
-```
-对于更复杂的映射,你可以添加实现`ErrorViewResolver`接口的beans:
-```java
-public class MyErrorViewResolver implements ErrorViewResolver {
-
- @Override
- public ModelAndView resolveErrorView(HttpServletRequest request,
- HttpStatus status, Map model) {
- // Use the request or status to optionally return a ModelAndView
- return ...
- }
-
-}
-```
-你也可以使用Spring MVC特性,比如[@ExceptionHandler方法](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#mvc-exceptionhandlers)和[@ControllerAdvice](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#mvc-ann-controller-advice),`ErrorController`将处理所有未处理的异常。
-
-**映射Spring MVC以外的错误页面**
-
-对于不使用Spring MVC的应用,你可以通过`ErrorPageRegistrar`接口直接注册`ErrorPages`。该抽象直接工作于底层内嵌servlet容器,即使你没有Spring MVC的`DispatcherServlet`,它们仍旧可以工作。
-```java
-@Bean
-public ErrorPageRegistrar errorPageRegistrar(){
- return new MyErrorPageRegistrar();
-}
-
-// ...
-
-private static class MyErrorPageRegistrar implements ErrorPageRegistrar {
-
- @Override
- public void registerErrorPages(ErrorPageRegistry registry) {
- registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
- }
-
-}
-```
-注.如果你注册一个`ErrorPage`,该页面需要被一个`Filter`处理(在一些非Spring web框架中很常见,比如Jersey,Wicket),那么该`Filter`需要明确注册为一个`ERROR`分发器(dispatcher),例如:
-```java
-@Bean
-public FilterRegistrationBean myFilter() {
- FilterRegistrationBean registration = new FilterRegistrationBean();
- registration.setFilter(new MyFilter());
- ...
- registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
- return registration;
-}
-```
-(默认的`FilterRegistrationBean`不包含`ERROR` dispatcher类型)。
-
-**WebSphere应用服务器的错误处理**
-
-当部署到一个servlet容器时,Spring Boot通过它的错误页面过滤器将带有错误状态的请求转发到恰当的错误页面。request只有在response还没提交时才能转发(forwarded)到正确的错误页面,而WebSphere应用服务器8.0及后续版本默认情况会在servlet方法成功执行后提交response,你需要设置`com.ibm.ws.webcontainer.invokeFlushAfterService`属性为`false`来关闭该行为。
diff --git "a/IV. Spring Boot features/27.2 The \342\200\230Spring WebFlux framework\342\200\231.md" "b/IV. Spring Boot features/27.2 The \342\200\230Spring WebFlux framework\342\200\231.md"
deleted file mode 100644
index f6a672ee..00000000
--- "a/IV. Spring Boot features/27.2 The \342\200\230Spring WebFlux framework\342\200\231.md"
+++ /dev/null
@@ -1,62 +0,0 @@
-### 27.2 The ‘Spring WebFlux framework’
-
-Spring WebFlux is the new reactive web framework introduced in Spring Framework 5.0. Unlike Spring MVC, it does not require the Servlet API, is fully asynchronous and non-blocking, and implements the Reactive Streams specification through the Reactor project.
-
-Spring WebFlux comes in two flavors; the annotation-based one is quite close to the Spring MVC model we know:
-
-@RestController
-@RequestMapping("/users")
-public class MyRestController {
-
- @GetMapping("/{user}")
- public Mono getUser(@PathVariable Long user) {
- // ...
- }
-
- @GetMapping("/{user}/customers")
- Flux getUserCustomers(@PathVariable Long user) {
- // ...
- }
-
- @DeleteMapping("/{user}")
- public Mono deleteUser(@PathVariable Long user) {
- // ...
- }
-
-}
-‘WebFlux.fn’, the functional variant, separates the routing configuration from the actual handling of the requests:
-
-@Configuration
-public class RoutingConfiguration {
-
- @Bean
- public RouterFunction monoRouterFunction(UserHandler userHandler) {
- return route(GET("/{user}").and(accept(APPLICATION_JSON)), userHandler::getUser)
- .andRoute(GET("/{user}/customers").and(accept(APPLICATION_JSON)), userHandler::getUserCustomers)
- .andRoute(DELETE("/{user}").and(accept(APPLICATION_JSON)), userHandler::deleteUser);
- }
-
-}
-
-@Component
-public class UserHandler {
-
- public Mono getUser(ServerRequest request) {
- // ...
- }
-
- public Mono getUserCustomers(ServerRequest request) {
- // ...
- }
-
- public Mono deleteUser(ServerRequest request) {
- // ...
- }
-}
-WebFlux is part of the Spring Framework and detailed information is available in the reference documentation.
-
-To get started, add the spring-boot-starter-webflux module to your application.
-
-[Note]
-Adding both spring-boot-starter-web and spring-boot-starter-webflux modules in your application will result in Spring Boot auto-configuring Spring MVC, not WebFlux. This behavior has been chosen because many Spring developers will add spring-boot-starter-webflux to their Spring MVC application to use the reactive WebCLient. You can still enforce your choice by setting the chosen application type like SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE).
-
diff --git "a/IV. Spring Boot features/27.2 The \342\200\234Spring WebFlux Framework\342\200\235.md" "b/IV. Spring Boot features/27.2 The \342\200\234Spring WebFlux Framework\342\200\235.md"
new file mode 100644
index 00000000..faf29c8e
--- /dev/null
+++ "b/IV. Spring Boot features/27.2 The \342\200\234Spring WebFlux Framework\342\200\235.md"
@@ -0,0 +1,64 @@
+### 27.2 Spring WebFlux框架
+
+Spring WebFlux是Spring Framework 5.0中引入的新的响应式网络框架。不同与Spring MVC,它不需要Servlet API,是完全异步、非阻塞的,通过[Reactor项目](https://projectreactor.io/)实现了[Reactive Streams](http://www.reactive-streams.org/) 规范。
+
+Spring WebFlux有两种风格:函数式和基于注解。基于注解的风格相当接近于Spring MVC模型,如下所示:
+```java
+@RestController
+@RequestMapping("/users")
+public class MyRestController {
+
+ @GetMapping("/{user}")
+ public Mono getUser(@PathVariable Long user) {
+ // ...
+ }
+
+ @GetMapping("/{user}/customers")
+ public Flux getUserCustomers(@PathVariable Long user) {
+ // ...
+ }
+
+ @DeleteMapping("/{user}")
+ public Mono deleteUser(@PathVariable Long user) {
+ // ...
+ }
+
+}
+```
+“WebFlux.fn”——函数式变体,从请求的实际处理中分离了路由配置,如下所示:
+```java
+@Configuration
+public class RoutingConfiguration {
+
+ @Bean
+ public RouterFunction monoRouterFunction(UserHandler userHandler) {
+ return route(GET("/{user}").and(accept(APPLICATION_JSON)), userHandler::getUser)
+ .andRoute(GET("/{user}/customers").and(accept(APPLICATION_JSON)), userHandler::getUserCustomers)
+ .andRoute(DELETE("/{user}").and(accept(APPLICATION_JSON)), userHandler::deleteUser);
+ }
+
+}
+
+@Component
+public class UserHandler {
+
+ public Mono getUser(ServerRequest request) {
+ // ...
+ }
+
+ public Mono getUserCustomers(ServerRequest request) {
+ // ...
+ }
+
+ public Mono deleteUser(ServerRequest request) {
+ // ...
+ }
+}
+```
+WebFlux是Spring框架的一部分。详细信息请查看它的[参考文档](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web-reactive.html#webflux-fn)。
+
+**注** 你可以定义多个`RouterFunction` bean来模块化路由的定义。如果你需要应用优先级,可以给bean排序。
+
+给你的应用添加`spring-boot-starter-webflux`模块,开始使用。
+
+**注** 在你的应用里同时添加`spring-boot-starter-web`和`spring-boot-starter-webflux`模块,会使Spring Boot自动配置Spring MVC,而不是WebFlux。这种行为是因为许多Spring开发者为了使用响应式的`WebClient`,往他们的Spring MVC应用里添加`spring-boot-starter-webflux`。你可以设置应用类型为`SpringApplication.setWebApplicationType(WebApplicationType.REACTIVE)`,强制Spring Boot自动配置WebFlux。
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.2.1 Spring WebFlux Auto-configuration.md b/IV. Spring Boot features/27.2.1 Spring WebFlux Auto-configuration.md
new file mode 100644
index 00000000..6522e9ab
--- /dev/null
+++ b/IV. Spring Boot features/27.2.1 Spring WebFlux Auto-configuration.md
@@ -0,0 +1,11 @@
+### 27.2.1 Spring WebFlux自动配置
+
+Spring Boot为Spring WebFlux提供了自动配置。这些配置在大多数应用里能够很好地工作。
+
+自动配置会添加以下特性:
+- 为`HttpMessageReader`和`HttpMessageWriter`实例配置编解码器([在此文档的后面章节](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-webflux-httpcodecs)有描述)。
+- 支持服务静态内容,包括对WebJars的支持 ([在此文档的后面章节](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-static-content)有描述)。
+
+如果你想保持Spring Boot WebFlux特性,并添加额外的[WebFlux配置](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/web.html#web-reactive),你可以添加你自己的`WebFluxConfigurer`类型的`@Configuration`类,但是不加`@EnableWebFlux`。
+
+如果你想完全控制Spring WebFlux,你可以添加你自己的`@Configuration`,并用`@EnableWebFlux`标注。
diff --git a/IV. Spring Boot features/27.2.1 Spring WebFlux auto-configuration.md b/IV. Spring Boot features/27.2.1 Spring WebFlux auto-configuration.md
deleted file mode 100644
index 95c0ab89..00000000
--- a/IV. Spring Boot features/27.2.1 Spring WebFlux auto-configuration.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 27.2.1 Spring WebFlux auto-configuration
-
-Spring Boot provides auto-configuration for Spring WebFlux that works well with most applications.
-
-The auto-configuration adds the following features on top of Spring’s defaults:
-
-Configuring codecs for HttpMessageReader and HttpMessageWriter instances (see below).
-Support for serving static resources, including support for WebJars (see below).
-If you want to keep Spring Boot WebFlux features, and you just want to add additional WebFlux configuration you can add your own @Configuration class of type WebFluxConfigurer, but without @EnableWebFlux.
-
-If you want to take complete control of Spring WebFlux, you can add your own @Configuration annotated with @EnableWebFlux.
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.2.2 HTTP Codecs with HttpMessageReaders and HttpMessageWriters.md b/IV. Spring Boot features/27.2.2 HTTP Codecs with HttpMessageReaders and HttpMessageWriters.md
new file mode 100644
index 00000000..eda3b239
--- /dev/null
+++ b/IV. Spring Boot features/27.2.2 HTTP Codecs with HttpMessageReaders and HttpMessageWriters.md
@@ -0,0 +1,23 @@
+### 27.2.2 HTTP编解码器——HttpMessageReaders与HttpMessageWriters
+
+Spring WebFlux使用`HttpMessageReader`和`HttpMessageWriter`接口转换HTTP请求与回应。它们由`CodecConfigurer`配置——通过查看类路径里可用的库配置默认值。
+
+Spring Boot通过使用`CodecCustomizer`实例,更进一步地实现自定义。比如,`spring.jackson.*`配置键被应用于Jackson编解码器。
+
+如果你需要添加或自定义编解码器,你可以创建一个自定义的`CodecCustomizer`组件,如下所示:
+```java
+import org.springframework.boot.web.codec.CodecCustomizer;
+
+@Configuration
+public class MyConfiguration {
+
+ @Bean
+ public CodecCustomizer myCodecCustomizer() {
+ return codecConfigurer -> {
+ // ...
+ }
+ }
+
+}
+```
+你也可以利用[Spring Boot的自定义JSON序列化器和反序列化器](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-json-components)。
diff --git a/IV. Spring Boot features/27.2.2 HTTP codecs with HttpMessageReaders and HttpMessageWriters.md b/IV. Spring Boot features/27.2.2 HTTP codecs with HttpMessageReaders and HttpMessageWriters.md
deleted file mode 100644
index 56f5f96b..00000000
--- a/IV. Spring Boot features/27.2.2 HTTP codecs with HttpMessageReaders and HttpMessageWriters.md
+++ /dev/null
@@ -1,22 +0,0 @@
-### 27.2.2 HTTP codecs with HttpMessageReaders and HttpMessageWriters
-
-Spring WebFlux uses the HttpMessageReader and HttpMessageWriter interface to convert HTTP requests and responses. They are configured with CodecConfigurer with sensible defaults, by looking at the libraries available in your classpath.
-
-Spring Boot will apply further customization using CodecCustomizer instances. For example, spring.jackson.* configuration keys will be applied to the Jackson codec.
-
-If you need to add or customize codecs you can create a custom CodecCustomizer component:
-
-import org.springframework.boot.web.codec.CodecCustomizer;
-
-@Configuration
-public class MyConfiguration {
-
- @Bean
- public CodecCustomizer myCodecCustomizer() {
- return codecConfigurer -> {
- // ...
- }
- }
-
-}
-You can also leverage Boot’s custom JSON serializers and deserializers.
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.2.3 Static Content.md b/IV. Spring Boot features/27.2.3 Static Content.md
index 8fcb2966..bc8c64d0 100644
--- a/IV. Spring Boot features/27.2.3 Static Content.md
+++ b/IV. Spring Boot features/27.2.3 Static Content.md
@@ -1,13 +1,13 @@
-### 27.2.3 Static Content
+### 27.2.3 静态内容
-By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath. It uses the ResourceWebHandler from Spring WebFlux so you can modify that behavior by adding your own WebFluxConfigurer and overriding the addResourceHandlers method.
+默认情况下,Spring Boot从类路径下的`/static`(或者是`/public`、`/resources`、`/META-INF/resources`)文件夹提供静态内容。这是通过Spring WebFlux的`ResourceWebHandler`实现的。你可以添加你自己的`WebFluxConfigurer`并覆写`addResourceHandlers`方法来改变该行为(加载静态文件)。
-By default, resources are mapped on /** but you can tune that via spring.mvc.static-path-pattern. For instance, relocating all resources to /resources/** can be achieved as follows:
+默认地,资源放置在`/**`,但是你可以通过`spring.webflux.static-path-pattern`属性进行调整。例如,迁移所有的资源到`/resources/**`可以按照如下方式实现:
+```properties
+spring.webflux.static-path-pattern=/resources/**
+```
+你可以设置`spring.resources.static-locations`属性自定义静态资源的位置(配置一系列目录位置代替默认的值)。这样,Spring Boot会在你自定义的位置查找欢迎页。所以,要是在哪个位置有`index.html`,它就会是应用的主页。
-spring.mvc.static-path-pattern=/resources/**
-You can also customize the static resource locations using spring.resources.static-locations (replacing the default values with a list of directory locations). If you do this the default welcome page detection will switch to your custom locations, so if there is an index.html in any of your locations on startup, it will be the home page of the application.
+此外,除了上述标准的静态资源位置,有个例外情况是[Webjars内容](http://www.webjars.org/)。任何在`/webjars/**`路径下的资源都将从jar文件中提供,只要它们以Webjars的格式打包。
-In addition to the ‘standard’ static resource locations above, a special case is made for Webjars content. Any resources with a path in /webjars/** will be served from jar files if they are packaged in the Webjars format.
-
-[Tip]
-Spring WebFlux applications don’t strictly depend on the Servlet API, so they can’t be deployed as war and have no use of the src/main/webapp directory.
+**注** Spring WebFlux应用并不完全依赖Servlet API,所以它们不能用war文件部署,也不使用`src/main/webapp`目录。
diff --git a/IV. Spring Boot features/27.2.4 Template Engines.md b/IV. Spring Boot features/27.2.4 Template Engines.md
new file mode 100644
index 00000000..bb7d4dd0
--- /dev/null
+++ b/IV. Spring Boot features/27.2.4 Template Engines.md
@@ -0,0 +1,11 @@
+### 27.2.4 模板引擎
+
+除了REST网络服务,你也可以将Spring WebFlux用于动态HTML内容。Spring WebFlux支持许多的模板技术,包括Thymeleaf、FreeMarker与Mustache。
+
+Spring Boot支持以下模板引擎的自动配置:
+
+- [FreeMarker](http://freemarker.org/docs/)
+- [Thymeleaf](http://www.thymeleaf.org/)
+- [Mustache](https://mustache.github.io/)
+
+当你用默认配置使用这些模板引擎时,你的模板会自动从`src/main/resources/templates`获取。
diff --git a/IV. Spring Boot features/27.2.4 Template engines.md b/IV. Spring Boot features/27.2.4 Template engines.md
deleted file mode 100644
index 16db8acc..00000000
--- a/IV. Spring Boot features/27.2.4 Template engines.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 27.2.4 Template engines
-
-As well as REST web services, you can also use Spring WebFlux to serve dynamic HTML content. Spring WebFlux supports a variety of templating technologies including Thymeleaf, FreeMarker and Mustache.
-
-Spring Boot includes auto-configuration support for the following templating engines:
-
-FreeMarker
-Thymeleaf
-Mustache
-When you’re using one of these templating engines with the default configuration, your templates will be picked up automatically from src/main/resources/templates.
diff --git a/IV. Spring Boot features/27.2.5 Error Handling.md b/IV. Spring Boot features/27.2.5 Error Handling.md
new file mode 100644
index 00000000..7196c286
--- /dev/null
+++ b/IV. Spring Boot features/27.2.5 Error Handling.md
@@ -0,0 +1,55 @@
+### 27.2.5 错误处理
+
+Spring Boot提供了`WebExceptionHandler`,用一种明智的方式处理所有的错误。在处理顺序上,它的位置在WebFlux提供处理器之前。对于机器客户端,它会产生带有错误的详细描述(HTTP状态与异常信息)的JSON响应。对于浏览器客户端,“whitelabel”错误处理器会以HTML格式渲染相同的数据。你也可以提供你自己的HTML模版来显示错误(查看[下一章节](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-webflux-error-handling-custom-error-pages))。
+
+自定义这个特性的第一步时常需要使用现存的机制,但是替换或者添加错误的内容。为此,你可以添加`ErrorAttributes`类型的bean。
+
+为了改变错误处理的行为,你可以实现`ErrorWebExceptionHandler`,并注册一个那种类型的bean定义。因为 `WebExceptionHandler`的级别相当低,Spring Boot提供了方便的`AbstractErrorWebExceptionHandler`,让你以WebFlux函数式方法处理错误,如下所示:
+```java
+public class CustomErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler {
+
+ // Define constructor here
+
+ @Override
+ protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) {
+
+ return RouterFunctions
+ .route(aPredicate, aHandler)
+ .andRoute(anotherPredicate, anotherHandler);
+ }
+
+}
+```
+你也可以直接继承`DefauLambdatErrorWebExceptionHandler`,并重写特定的方法。
+
+**自定义错误页**
+
+如果你想要给某个给定的状态码显示自定义的HTML错误页,你可以在`/error`文件夹下添加一个文件。错误页可以是静态的HTML(也就是,添加在任何的静态资源文件夹下面),或者使用模版构建。文件名应当是状态码,或者是一系列掩码。
+
+比如,为了将`404`映射到一个静态HTML文件,你的文件夹结构将会如下:
+
+```
+src/
+ +- main/
+ +- java/
+ | +
+ +- resources/
+ +- public/
+ +- error/
+ | +- 404.html
+ +-
+```
+
+使用Mustache模版映射所有的`5xx`错误,你的文件夹结构将会如下:
+
+```
+src/
+ +- main/
+ +- java/
+ | +
+ +- resources/
+ +- templates/
+ +- error/
+ | +- 5xx.mustache
+ +-
+```
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.2.6 Web Filters.md b/IV. Spring Boot features/27.2.6 Web Filters.md
new file mode 100644
index 00000000..5daad3e5
--- /dev/null
+++ b/IV. Spring Boot features/27.2.6 Web Filters.md
@@ -0,0 +1,11 @@
+### 27.2.6 网络过滤器
+
+Spring WebFlux提供了`WebFilter`接口。它可以用来过滤HTTP请求-响应交换。在应用上下文里的`WebFilter`将会自动用于过滤每一个交换。
+
+过滤器的顺序很重要。它们可以实现`Ordered`,或者标注`@Order`。Spring Boot会为你自动配置网络过滤器,顺序如下:
+
+|Web Filter|Order|
+|--|--|
+|`MetricsWebFilter`|`Ordered.HIGHEST_PRECEDENCE + 1`|
+|`WebFilterChainProxy `(Spring Security)|`-100`|
+|`HttpTraceWebFilter`|`Ordered.LOWEST_PRECEDENCE - 10`|
\ No newline at end of file
diff --git a/IV. Spring Boot features/27.3. JAX-RS and Jersey.md b/IV. Spring Boot features/27.3. JAX-RS and Jersey.md
index e3582a67..c9c39df5 100644
--- a/IV. Spring Boot features/27.3. JAX-RS and Jersey.md
+++ b/IV. Spring Boot features/27.3. JAX-RS and Jersey.md
@@ -2,7 +2,7 @@
如果你更喜欢JAX-RS为REST端点提供的编程模型,可以使用相应的实现代替Spring MVC。如果将Jersey 1.x和Apache CXF的`Servlet`或`Filter`注册到应用上下文中,那它们可以很好的工作。Spring对Jersey 2.x有一些原生支持,所以在Spring Boot中也为它提供了自动配置及一个starter。
-想要使用Jersey 2.x,只需添加`spring-boot-starter-jersey`依赖,然后创建一个`ResourceConfig`类型的`@Bean`,用于注册所有的端点(endpoints):
+想要使用Jersey 2.x,需要添加`spring-boot-starter-jersey`依赖,然后创建一个`ResourceConfig`类型的`@Bean`,用于注册所有的端点(endpoints),如下所示:
```java
@Component
public class JerseyConfig extends ResourceConfig {
@@ -15,7 +15,7 @@ public class JerseyConfig extends ResourceConfig {
你也可以注册任意数量的,实现`ResourceConfigCustomizer`的beans来进一步自定义。
-所有注册的端点都需注解`@Components`和HTTP资源annotations(比如`@GET`):
+所有注册的端点都需注解`@Components`和HTTP资源annotations(比如`@GET`),如下所示:
```java
@Component
@Path("/hello")
@@ -26,8 +26,8 @@ public class Endpoint {
}
}
```
-由于`Endpoint`是一个Spring组件(`@Component`),所以它的生命周期受Spring管理,你可以使用`@Autowired`添加依赖,也可以使用`@Value`注入外部配置。Jersey的servlet会被注册,并默认映射到`/*`,你可以将`@ApplicationPath`添加到`ResourceConfig`来改变该映射。
+由于`Endpoint`是一个Spring组件(`@Component`),所以它的生命周期受Spring管理,你可以使用`@Autowired`注解注入依赖,也可以使用`@Value`注解注入外部配置。Jersey的servlet会被注册,并默认映射到`/*`,你可以将`@ApplicationPath`添加到`ResourceConfig`来改变该映射。
-默认情况下,Jersey将以Servlet的形式注册为一个`ServletRegistrationBean`类型的`@Bean`,name为`jerseyServletRegistration`,该servlet默认会延迟初始化,不过可以通过`spring.jersey.servlet.load-on-startup`自定义。通过创建相同name的bean,你可以禁用或覆盖框架默认产生的bean。设置`spring.jersey.type=filter`可以使用Filter的形式代替Servlet,相应的`@Bean`类型变为`jerseyFilterRegistration`,该filter有一个`@Order`属性,你可以通过`spring.jersey.filter.order`设置。Servlet和Filter注册时都可以使用`spring.jersey.init.*`定义一个属性集合传递给init参数。
+默认情况下,Jersey将以Servlet的形式注册为一个`ServletRegistrationBean`类型的`@Bean`,name为`jerseyServletRegistration`,该servlet默认会延迟初始化,不过可以通过`spring.jersey.servlet.load-on-startup`自定义。通过创建相同name的bean,你可以禁用或覆盖框架默认产生的bean。设置`spring.jersey.type=filter`可以使用filter的形式代替servlet,相应的`@Bean`类型变为`jerseyFilterRegistration`,该filter有一个`@Order`属性,你可以通过`spring.jersey.filter.order`设置。servlet和filter注册时都可以使用`spring.jersey.init.*`定义一个属性集合传递给init参数。
-这里有一个[Jersey示例](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-samples/spring-boot-sample-jersey),你可以查看如何设置相关事项。
+这里有一个[Jersey示例](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-samples/spring-boot-sample-jersey),你可以查看如何设置相关事项。还有一个[Jersey 1.x示例](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-samples/spring-boot-sample-jersey1)。注意,在Jersey 1.x示例里,spring-boot maven plugin被配置为拆开某些Jersey jars。这样,它们就会被JAX-RS实现扫描(因为示例要求它们在`Filter`注册里接受扫描)。如果你的JAX-RS资源以内部jars的方法打包,你可能需要做同样的事情。
diff --git a/IV. Spring Boot features/27.4 Embedded Servlet Container Support.md b/IV. Spring Boot features/27.4 Embedded Servlet Container Support.md
new file mode 100644
index 00000000..065c71cd
--- /dev/null
+++ b/IV. Spring Boot features/27.4 Embedded Servlet Container Support.md
@@ -0,0 +1,5 @@
+### 27.4 内嵌servlet容器支持
+
+Spring Boot支持内嵌的Tomcat、Jetty和Undertow服务器。多数开发者使用合适的"Starter"来获取一个完全配置好的实例即可。内嵌服务器默认监听8080端口的HTTP请求。
+
+**警告⚠️** 如果你在CentOS上使用Tomcat,需要注意:默认情况下,一个临时的目录会被用于存储编译完成的JSPs和上传的文件等。当你的应用运行时出错,这个目录可能会被`tmpwatch`删除。为了避免这种情况,你需要自定义`tmpwatch`。这样`tomcat.*`目录才不会被删除。或者,配置`server.tomcat.basedir`。这样内嵌的Tomcat会使用一个不同的位置。
diff --git a/IV. Spring Boot features/27.4 Embedded servlet container support.md b/IV. Spring Boot features/27.4 Embedded servlet container support.md
deleted file mode 100644
index 856d740a..00000000
--- a/IV. Spring Boot features/27.4 Embedded servlet container support.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 27.4 内嵌servlet容器支持
-
-Spring Boot支持内嵌的Tomcat, Jetty和Undertow服务器,多数开发者只需要使用合适的'Starter'来获取一个完全配置好的实例即可,内嵌服务器默认监听8080端口的HTTP请求。
-
-**警告⚠️** 如果你在CentOS上使用Tomcat,需要注意:默认情况下,一个临时的目录会被用于存储编译完成的JSPs和上传的文件等。当你的应用运行时出错,这个目录可能会被`tmpwatch`删除。为了避免这种情况,你需要自定义`tmpwatch`。这样`tomcat.*`目录才不会被删除。或者,配置`server.tomcat.basedir`。这样内嵌的Tomcat会使用一个不同的位置。
diff --git a/IV. Spring Boot features/27.4.1 Servlets, Filters, and listeners.md b/IV. Spring Boot features/27.4.1 Servlets, Filters, and listeners.md
index 9fa91a51..310ffb5a 100644
--- a/IV. Spring Boot features/27.4.1 Servlets, Filters, and listeners.md
+++ b/IV. Spring Boot features/27.4.1 Servlets, Filters, and listeners.md
@@ -1,9 +1,22 @@
-### 27.4.1 Servlets, Filters和listeners
+### 27.4.1 Servlets、Filters和listeners
-使用内嵌servlet容器时,你可以通过使用Spring beans或扫描Servlet组件的方式注册Servlets,Filters及特定Servlet相关的所有listeners(比如`HttpSessionListener`)。
+使用内嵌servlet容器时,你可以通过使用Spring beans或扫描Servlet组件的方式注册servlets,filters及特定Servlet相关的所有listeners(比如`HttpSessionListener`)。
-**将Servlets,Filters和listeners注册为Spring beans**
+**将Servlet、Filter和listener注册为Spring bean**
-所有`Servlet`,`Filter`或Servlet `*Listener`实例,只要是Spring bean,都会注册到内嵌容器中。如果想在配置期间引用`application.properties`的属性,这是非常方便的。默认情况下,如果上下文只包含单个Servlet,那它将被映射到`/`。如果存在多个Servlet beans,那么bean的名称将被用作路径的前缀,过滤器将映射到`/*`。
+所有`Servlet`,`Filter`或servlet `*Listener`实例,只要是Spring bean,都会注册到内嵌容器中。如果想在配置期间引用`application.properties`的属性,这是非常方便的。默认情况下,如果上下文只包含单个Servlet,那它将被映射到`/`。如果存在多个servlet beans,那么bean的名称将被用作路径的前缀,过滤器将映射到`/*`。
如果基于约定(convention-based)的映射不够灵活,你可以使用`ServletRegistrationBean`,`FilterRegistrationBean`,`ServletListenerRegistrationBean`实现完全的控制。
+
+Spring Boot带有许多的自动配置。它们可能定义Filter bean。这里有一些Filter以及它们的顺序的例子(低位意味着更高的优先级)。
+
+| Servlet Filter | Order |
+|----------|-------------|
+| `OrderedCharacterEncodingFilter` | `Ordered.HIGHEST_PRECEDENCE` |
+| `WebMvcMetricsFilter` | `Ordered.HIGHEST_PRECEDENCE + 1` |
+| `ErrorPageFilter` | `Ordered.HIGHEST_PRECEDENCE + 1` |
+| `HttpTraceFilter` | `Ordered.LOWEST_PRECEDENCE - 10` |
+
+无序的Filter bean通常是安全的。
+
+如果需要一个特定的顺序,你应当避免配置一个在`Ordered.HIGHEST_PRECEDENCE`上读取请求体的Filter。因为它可能违反你的应用的字符编码配置。如果一个Servlet filter包裹请求,它应当被配置一个顺序。此顺序不高于`FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER`。
diff --git a/IV. Spring Boot features/27.4.2 Servlet Context Initialization.md b/IV. Spring Boot features/27.4.2 Servlet Context Initialization.md
index 77536d3a..9ad6372c 100644
--- a/IV. Spring Boot features/27.4.2 Servlet Context Initialization.md
+++ b/IV. Spring Boot features/27.4.2 Servlet Context Initialization.md
@@ -1,4 +1,5 @@
### 27.4.2 Servlet上下文初始化
+
内嵌servlet容器不会直接执行Servlet 3.0+的`javax.servlet.ServletContainerInitializer`接口,或Spring的`org.springframework.web.WebApplicationInitializer`接口,这样设计的目的是降低war包内运行的第三方库破坏Spring Boot应用的风险。
如果需要在Spring Boot应用中执行servlet上下文初始化,你需要注册一个实现`org.springframework.boot.web.servlet.ServletContextInitializer`接口的bean。`onStartup`方法可以获取`ServletContext`,如果需要的话可以轻松用来适配一个已存在的`WebApplicationInitializer`。
diff --git a/IV. Spring Boot features/27.4.3 The ServletWebServerApplicationContext.md b/IV. Spring Boot features/27.4.3 The ServletWebServerApplicationContext.md
index 3a499574..fe9a1afc 100644
--- a/IV. Spring Boot features/27.4.3 The ServletWebServerApplicationContext.md
+++ b/IV. Spring Boot features/27.4.3 The ServletWebServerApplicationContext.md
@@ -1,5 +1,5 @@
### 27.4.3 The ServletWebServerApplicationContext
-Spring Boot底层使用一种新的`ApplicationContext`类型,用于对内嵌servlet容器的支持。`ServletWebServerApplicationContext`是一种特殊类型的`WebApplicationContext`,它通过搜索到的单个`ServletWebServerFactory` bean来启动自己,通常`TomcatServletWebServerFactory`,`JettyServletWebServerFactory`或`UndertowServletWebServerFactory`将被自动配置。
+Spring Boot底层使用一种不同的`ApplicationContext`类型,用于对内嵌servlet容器的支持。`ServletWebServerApplicationContext`是一种特殊类型的`WebApplicationContext`,它通过搜索到的单个`ServletWebServerFactory` bean来启动自己,通常`TomcatServletWebServerFactory`,`JettyServletWebServerFactory`或`UndertowServletWebServerFactory`将被自动配置。
-**注** 你不需要关心这些实现类,大部分应用都能被自动配置,并根据你的行为创建合适的`ApplicationContext`和`ServletWebServerFactory`。
+**注** 你通常不需要关心这些实现类,大部分应用都能被自动配置,并根据你的行为创建合适的`ApplicationContext`和`ServletWebServerFactory`。
diff --git a/IV. Spring Boot features/27.4.4 Customizing Embedded Servlet Containers.md b/IV. Spring Boot features/27.4.4 Customizing Embedded Servlet Containers.md
new file mode 100644
index 00000000..a94b2c43
--- /dev/null
+++ b/IV. Spring Boot features/27.4.4 Customizing Embedded Servlet Containers.md
@@ -0,0 +1,47 @@
+### 27.4.4 自定义内嵌servlet容器
+
+常见的Servlet容器配置可以通过Spring `Environment`进行设置,通常将这些属性定义到`application.properties`文件中。
+
+常见的服务器配置包括:
+
+1. 网络设置:监听进入Http请求的端口(`server.port`),接口绑定地址`server.address`等。
+2. Session设置:session是否持久化(`server.servlet.session.persistence`),session超时时间(`server.servlet.session.timeout`),数据存放位置(`server.servlet.session.store-dir`),session-cookie配置(`server.servlet.session.cookie.*`)。
+3. Error管理:错误页面的位置(`server.error.path`)等。
+4. [SSL](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-configure-ssl)。
+5. [HTTP压缩](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#how-to-enable-http-response-compression)
+
+Spring Boot会尽量暴露常用设置,但这并不总是可能的。对于不可能的情况,可以使用专用的命名空间提供server-specific配置(查看`server.tomcat`,`server.undertow`)。例如,可以根据内嵌servlet容器的特性对[access logs](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-configure-accesslogs)进行不同的设置。
+
+**注** 具体参考[ServerProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java)。
+
+**编程方式的自定义**
+
+如果需要以编程方式配置内嵌servlet容器,你可以注册一个实现`WebServerFactoryCustomizer`接口的Spring bean。`WebServerFactoryCustomizer`能够获取到包含很多自定义setter方法的`ConfigurableServletWebServerFactory`,你可以通过这些setter方法对内嵌容器自定义。Tomcat,Jetty和Undertow有独立的变体。下面的例子展示了以编程的方式设置端口:
+```java
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
+import org.springframework.stereotype.Component;
+
+@Component
+public class CustomizationBean implements WebServerFactoryCustomizer {
+ @Override
+ public void customize(ConfigurableServletWebServerFactory server) {
+ server.setPort(9000);
+ }
+}
+```
+
+**直接自定义ConfigurableServletWebServerFactory**
+
+如果以上自定义手法过于受限,你可以自己注册`TomcatServletWebServerFactory`,`JettyServletWebServerFactory`或`UndertowServletWebServerFactory`。
+```java
+@Bean
+public ConfigurableServletWebServerFactory webServerFactory() {
+ TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
+ factory.setPort(9000);
+ factory.setSessionTimeout(10, TimeUnit.MINUTES);
+ factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html");
+ return factory;
+}
+```
+很多配置选项提供setter方法,有的甚至提供一些受保护的钩子方法以满足你的某些特殊需求,具体参考源码或相关文档。
diff --git a/IV. Spring Boot features/27.4.4 Customizing embedded servlet containers.md b/IV. Spring Boot features/27.4.4 Customizing embedded servlet containers.md
deleted file mode 100644
index 98b638b0..00000000
--- a/IV. Spring Boot features/27.4.4 Customizing embedded servlet containers.md
+++ /dev/null
@@ -1,47 +0,0 @@
-### 27.4.4 自定义内嵌servlet容器
-
-常见的Servlet容器配置可以通过Spring `Environment`进行设置,通常将这些属性定义到`application.properties`文件中。
-
-常见的服务器配置包括:
-
-1. 网络设置:监听进入Http请求的端口(`server.port`),接口绑定地址`server.address`等。
-2. Session设置:session是否持久化(`server.session.persistence`),session超时时间(`server.session.timeout`),session数据存放位置(`server.session.store-dir`),session-cookie配置(`server.session.cookie.*`)。
-3. Error管理:错误页面的位置(`server.error.path`)等。
-4. [SSL](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#howto-configure-ssl)。
-5. [HTTP压缩](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#how-to-enable-http-response-compression)
-
-Spring Boot会尽量暴露常用设置,但这并不总是可能的。对于不可能的情况,可以使用专用的命名空间提供server-specific配置(查看`server.tomcat`,`server.undertow`)。例如,可以根据内嵌servlet容器的特性对[access logs](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#howto-configure-accesslogs)进行不同的设置。
-
-**注** 具体参考[ServerProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java)。
-
-**编程方式的自定义**
-
-如果需要以编程方式配置内嵌servlet容器,你可以注册一个实现`WebServerFactoryCustomizer`接口的Spring bean。`WebServerFactoryCustomizer`能够获取到包含很多自定义setter方法的`ConfigurableServletWebServerFactory`,你可以通过这些setter方法对内嵌容器自定义。
-```java
-import org.springframework.boot.web.server.WebServerFactoryCustomizer;
-import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CustomizationBean implements WebServerFactoryCustomizer {
- @Override
- public void customize(ConfigurableServletWebServerFactory server) {
- server.setPort(9000);
- }
-}
-```
-
-**直接自定义ConfigurableServletWebServerFactory**
-
-如果以上自定义手法过于受限,你可以自己注册`TomcatServletWebServerFactory`,`JettyServletWebServerFactory`或`UndertowServletWebServerFactory`。
-```java
-@Bean
-public ConfigurableServletWebServerFactory webServerFactory() {
- TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
- factory.setPort(9000);
- factory.setSessionTimeout(10, TimeUnit.MINUTES);
- factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html");
- return factory;
-}
-```
-很多配置选项提供setter方法,有的甚至提供一些受保护的钩子方法以满足你的某些特殊需求,具体参考源码或相关文档。
diff --git a/IV. Spring Boot features/27.4.5 JSP Limitations.md b/IV. Spring Boot features/27.4.5 JSP Limitations.md
new file mode 100644
index 00000000..7b19d07d
--- /dev/null
+++ b/IV. Spring Boot features/27.4.5 JSP Limitations.md
@@ -0,0 +1,10 @@
+### 27.4.5 JSP的限制
+
+当使用内嵌servlet容器运行Spring Boot应用时(并打包成一个可执行的存档archive),容器对JSP的支持有一些限制:
+
+1. Tomcat只支持war的打包方式,不支持可执行jar。
+2. Jetty只支持war的打包方式。
+3. Undertow不支持JSPs。
+4. 创建的自定义`error.jsp`页面不会覆盖默认的[error handling](http://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-error-handling)视图。
+
+这里有个[JSP示例](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp),你可以查看如何设置相关事项。
diff --git a/IV. Spring Boot features/27.4.5 JSP limitations.md b/IV. Spring Boot features/27.4.5 JSP limitations.md
deleted file mode 100644
index 927de6b5..00000000
--- a/IV. Spring Boot features/27.4.5 JSP limitations.md
+++ /dev/null
@@ -1,10 +0,0 @@
-### 27.4.5 JSP的限制
-
-当使用内嵌servlet容器运行Spring Boot应用时(并打包成一个可执行的存档archive),容器对JSP的支持有一些限制:
-
-1. Tomcat只支持war的打包方式,不支持可执行jar。
-2. Jetty只支持war的打包方式。
-3. Undertow不支持JSPs。
-4. 创建的自定义`error.jsp`页面不会覆盖默认的[error handling](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-error-handling)视图。
-
-这里有个[JSP示例](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-jsp),你可以查看如何设置相关事项。
diff --git a/IV. Spring Boot features/28. Security.md b/IV. Spring Boot features/28. Security.md
index 21374080..ec2acace 100644
--- a/IV. Spring Boot features/28. Security.md
+++ b/IV. Spring Boot features/28. Security.md
@@ -1,29 +1,19 @@
### 28. 安全
-如果添加了Spring Security的依赖,那么web应用默认对所有的HTTP路径(也称为终点,端点,表示API的具体网址)使用'basic'认证。为了给web应用添加方法级别(method-level)的保护,你可以添加`@EnableGlobalMethodSecurity`并使用想要的设置,其他信息参考[Spring Security Reference](http://docs.spring.io/spring-security/site/docs/4.1.3.RELEASE/reference/htmlsingle#jc-method)。
+如果Spring Security在类路径上,那么web应用默认是安全的。Spring Boot依靠Spring Security的内容协商策略,决定是使用httpBasic,还是formLogin。为了给web应用添加方法级别(method-level)的保护,你可以添加`@EnableGlobalMethodSecurity`并使用想要的设置。其它信息参考[Spring Security参考指南](https://docs.spring.io/spring-security/site/docs/5.0.3.RELEASE/reference/htmlsingle#jc-method)。
-默认的`AuthenticationManager`只有一个用户('user'的用户名和随机密码会在应用启动时以INFO日志级别打印出来),如下:
+默认的`AuthenticationManager`只有一个用户。用户名是user,密码随机,会在应用启动时以INFO日志级别打印出来。如下:
```java
-Using default security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35
+Using generated security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35
```
**注** 如果你对日志配置进行微调,确保`org.springframework.boot.autoconfigure.security`类别记录日志级别为`INFO`,否则默认的密码不会打印出来。
-你可以通过设置`security.user.password`改变默认密码,这些和其他有用的属性通过[SecurityProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java)(以"security"为前缀的属性)被外部化了。
+你可以通过提供`spring.security.user.name`和`spring.security.user.password`,改变用户名和密码。
-默认的安全配置是通过`SecurityAutoConfiguration`,`SpringBootWebSecurityConfiguration`(用于web安全),`AuthenticationManagerConfiguration`(可用于非web应用的认证配置)进行管理的。你可以添加一个`@EnableWebSecurity` bean来彻底关掉Spring Boot的默认配置。为了对它进行自定义,你需要使用外部的属性配置和`WebSecurityConfigurerAdapter`类型的beans(比如,添加基于表单的登陆)。
+在web应用中,你默认能得到如下的基本特性:
-**注** 如果你添加`@EnableWebSecurity`,同时也禁用了执行器安全,你将在整个应用里得到默认的基于表单的登录,除非你添加了一个自定义的`WebSecurityConfigurerAdapter`。
+- 一个`UserDetailsService`(如果是WebFlux应用的话,则是`ReactiveUserDetailsService`)bean,存储在内存中。还有一个用户,用户的密码是生成的(关于这个用户的属性,请查看[`SecurityProperties.User`](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/org/springframework/boot/autoconfigure/security/SecurityProperties.User.html))。
+- 应用在整个应用上的基于表单的登录或是HTTP Basic security(取决于Content-Type)。如果执行器在类路径上,则包含执行器端点。
+- 一个`DefaultAuthenticationEventPublisher`,用来发布认证事件。
-想要关闭认证管理的配置,你可以添加一个`AuthenticationManager`类型的bean,或在`@Configuration`类的某个方法里注入`AuthenticationManagerBuilder`来配置全局的`AuthenticationManager`。这里有一些安全相关的[Spring Boot应用示例](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-samples/)可以拿来参考。
-
-在web应用中你能得到的开箱即用的基本特性如下:
-
-1. 一个使用内存存储的`AuthenticationManager` bean和一个用户(查看`SecurityProperties.User`获取user的属性)。
-2. 忽略(不保护)常见的静态资源路径(`/css/**, /js/**, /images/**`,`/webjars/**`和 `**/favicon.ico`)。
-3. 对其他所有路径实施HTTP Basic安全保护。
-4. 安全相关的事件会发布到Spring的`ApplicationEventPublisher`(成功和失败的认证,拒绝访问)。
-5. Spring Security提供的常见底层特性(HSTS, XSS, CSRF, 缓存)默认都被开启。
-
-上述所有特性都能通过外部配置(`security.*`)打开,关闭,或修改。想要覆盖访问规则而不改变其他自动配置的特性,你可以添加一个注解`@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)`的`WebSecurityConfigurerAdapter`类型的`@Bean`。
-
-**注** `WebSecurityConfigurerAdapter`默认会匹配所有路径,如果不想完全覆盖Spring Boot自动配置的访问规则,你可以精确的配置想要覆盖的路径。
+你可以通过添加一个bean,为它提供一个不同的`AuthenticationEventPublisher`。
diff --git a/IV. Spring Boot features/28.1 MVC Security.md b/IV. Spring Boot features/28.1 MVC Security.md
new file mode 100644
index 00000000..a75f03e1
--- /dev/null
+++ b/IV. Spring Boot features/28.1 MVC Security.md
@@ -0,0 +1,7 @@
+### 28.1 MVC安全
+
+默认的安全配置由`SecurityAutoConfiguration`以及从其它地方导入的类(`SpringBootWebSecurityConfiguration`用于web安全,`AuthenticationManagerConfiguration`用于认证配置,也与非web应用相关)实现的。你可以添加一个`WebSecurityConfigurerAdapter`类型的bean,来彻底关掉默认的web应用安全配置(这样做不会禁用认证管理者配置或者Actuator的安全)。
+
+为了关闭认证管理者配置,你可以添加`UserDetailsService`、`AuthenticationProvider`、或是`AuthenticationManager`类型的bean。在[Spring Boot示例](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-samples/)里有几个安全的应用,里面包含了一些常见用例。
+
+访问规则可以通过添加自定义的`WebSecurityConfigurerAdapter`覆盖。Spring Boot提供了便捷的方法。它们可以用来覆盖执行器端点和静态资源的访问规则。`EndpointRequest`可以用来创建基于`management.endpoints.web.base-path`属性的`RequestMatcher`。`PathRequest`可以用来创建常用位置上的资源的`RequestMatcher`。
diff --git a/IV. Spring Boot features/28.1 OAuth2.md b/IV. Spring Boot features/28.1 OAuth2.md
deleted file mode 100644
index 80792651..00000000
--- a/IV. Spring Boot features/28.1 OAuth2.md
+++ /dev/null
@@ -1,3 +0,0 @@
-###28.1 OAuth2
-如果添加了`spring-security-oauth2`依赖,你可以利用自动配置简化认证(Authorization)或资源服务器(Resource Server)的设置,详情参考[Spring Security OAuth 2 Developers Guide](http://projects.spring.io/spring-security-oauth/docs/oauth2.html)。
-
diff --git a/IV. Spring Boot features/28.1.1 Authorization Server.md b/IV. Spring Boot features/28.1.1 Authorization Server.md
deleted file mode 100644
index d864b965..00000000
--- a/IV. Spring Boot features/28.1.1 Authorization Server.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 28.1.1 授权服务器
-
-想要创建一个授权服务器,并授予access tokens,你需要使用`@EnableAuthorizationServer`,并提供`security.oauth2.client.client-id`和`security.oauth2.client.client-secret`配置。
-
-按以上操作后,你就能使用客户端证书创建一个access token,例如:
-```shell
-$ curl client:secret@localhost:8080/oauth/token -d grant_type=password -d username=user -d password=pwd
-```
-`/token`端点basic形式的认证证书是`client-id`和`client-secret`,用户证书通常是Spring Security的user详情(Spring Boot中默认是"user"和一个随机的密码)。
-
-想要关闭自动配置,自己配置授权服务器特性,你只需添加一个`AuthorizationServerConfigurer`类型的`@Bean`。
diff --git a/IV. Spring Boot features/28.1.2 Resource Server.md b/IV. Spring Boot features/28.1.2 Resource Server.md
deleted file mode 100644
index b0ca0ec3..00000000
--- a/IV. Spring Boot features/28.1.2 Resource Server.md
+++ /dev/null
@@ -1,16 +0,0 @@
-### 28.1.2 资源服务器
-为了使用access token,你需要一个资源服务器(可以跟授权服务器是同一个)。创建资源服务器很简单,只需要添加`@EnableResourceServer`,提供一些配置以允许服务器解码access token。如果应用也是授权服务器,由于它知道如何去解码tokens,所以也就不需要做其他事情。如果你的app是独立的服务,那你就需要给它添加以下可选配置中的某一项:
-
-* `security.oauth2.resource.user-info-uri`用于`/me`资源(例如,PWS的`https://uaa.run.pivotal.io/userinfo`)。
-* `security.oauth2.resource.token-info-uri`用于token解码端点(例如,PWS的`https://uaa.run.pivotal.io/check_token`)。
-
-如果`user-info-uri`和`token-info-uri`都指定了,你可以设置flag筛选出最想要的那个(默认`prefer-token-info=true`)。
-
-另外,如果token是JWTs,你可以配置`security.oauth2.resource.jwt.key-value`解码它们(key是验签的key)。验签的键值可以是一个对称密钥,也可以是PEM编码的RSA公钥。如果你没有key,并且它是公开的,你可以通过`security.oauth2.resource.jwt.key-uri`提供一个下载URI(有一个"value"字段的JSON对象),例如,在PWS平台上:
-```
-$ curl https://uaa.run.pivotal.io/token_key
-{"alg":"SHA256withRSA","value":"-----BEGIN PUBLIC KEY-----\nMIIBI...\n-----END PUBLIC KEY-----\n"}
-```
-**注** 如果你使用`security.oauth2.resource.jwt.key-uri`,授权服务器需要在应用启动时也运行起来,如果找不到key,它将输出warning,并告诉你如何解决。
-
-OAuth2资源被过滤器链按`security.oauth2.resource.filter-order`指明的顺序保护着。默认地,在过滤器的保护结束之后才会到执行器端点(这样,执行器端点将会继续停留在HTTP Basic,除非你改变了顺序)。
diff --git a/IV. Spring Boot features/28.2 Token Type in User Info.md b/IV. Spring Boot features/28.2 Token Type in User Info.md
deleted file mode 100644
index df8aded9..00000000
--- a/IV. Spring Boot features/28.2 Token Type in User Info.md
+++ /dev/null
@@ -1,3 +0,0 @@
-###28.2 User Info中的Token类型
-
-Google和其他一些第三方身份(identity)提供商对发送给user info端点的请求头中设置的token类型名有严格要求。默认的`Bearer`满足大多数提供商要求,如果需要你可以设置`security.oauth2.resource.token-type`来改变它。
diff --git a/IV. Spring Boot features/28.2 WebFlux Security.md b/IV. Spring Boot features/28.2 WebFlux Security.md
new file mode 100644
index 00000000..1422d3dc
--- /dev/null
+++ b/IV. Spring Boot features/28.2 WebFlux Security.md
@@ -0,0 +1,23 @@
+### 28.2 WebFlux安全
+
+类似于Spring MVC应用,你可以通过添加`spring-boot-starter-security`依赖,保护你的WebFlux应用。默认的安全配置由`ReactiveSecurityAutoConfiguration`以及从其它地方导入的类(`WebFluxSecurityConfiguration`用于web安全,`ReactiveAuthenticationManagerConfiguration`用于认证配置,也与非web应用相关)实现的。你可以添加一个`WebFilterChainProxy`类型的bean,来彻底关掉默认的web应用安全配置(这样做不会禁用认证管理者配置或者Actuator的安全)。
+
+为了关闭认证管理者配置,你可以添加`ReactiveUserDetailsService`或是`ReactiveAuthenticationManager`类型的bean。
+
+访问规则可以通过添加自定义的`SecurityWebFilterChain`配置。Spring Boot提供了便捷的方法。它们可以用来覆盖执行器端点和静态资源的访问规则。`EndpointRequest`可以用来创建基于`management.endpoints.web.base-path`属性的`ServerWebExchangeMatcher`。
+
+`PathRequest`可以用来创建常用位置上的资源的`ServerWebExchangeMatcher`。
+
+例如,你可以添加如下代码,自定义你的安全配置:
+```java
+@Bean
+public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
+ http
+ .authorizeExchange()
+ .matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
+ .pathMatchers("/foo", "/bar")
+ .authenticated().and()
+ .formLogin();
+ return http.build();
+}
+```
\ No newline at end of file
diff --git a/IV. Spring Boot features/28.3 Customizing the User Info RestTemplate.md b/IV. Spring Boot features/28.3 Customizing the User Info RestTemplate.md
deleted file mode 100644
index 59d49b13..00000000
--- a/IV. Spring Boot features/28.3 Customizing the User Info RestTemplate.md
+++ /dev/null
@@ -1,14 +0,0 @@
-### 28.3 自定义User Info RestTemplate
-如果设置了`user-info-uri`,资源服务器在内部将使用一个`OAuth2RestTemplate`抓取用于认证的用户信息,这是一个类型为`UserInfoRestTemplateFactory`的`@Bean`提供的。默认适用于大多数提供商,但偶尔你可能需要添加其他interceptors,或改变request的验证器(authenticator)。想要添加自定义,只需创建一个`UserInfoRestTemplateCustomizer`类型的bean —— 它只有单个方法,在bean创建后,初始化前会调用该方法。此处自定义的rest template仅用于内部执行认证。或者,你可以定义你自己的`UserInfoRestTemplateFactory``@Bean`来掌握完全的控制。
-
-**注** 在YAML中设置RSA key时,需要使用管道符分割多行(“|”),记得缩进key value,例如:
-```yaml
-security:
- oauth2:
- resource:
- jwt:
- keyValue: |
- -----BEGIN PUBLIC KEY-----
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC...
- -----END PUBLIC KEY-----
-```
diff --git a/IV. Spring Boot features/28.3 OAuth2.md b/IV. Spring Boot features/28.3 OAuth2.md
new file mode 100644
index 00000000..bde053d0
--- /dev/null
+++ b/IV. Spring Boot features/28.3 OAuth2.md
@@ -0,0 +1,3 @@
+### 28.3 OAuth2
+
+[OAuth2](https://oauth.net/2/)是一个Spring支持的被广泛使用的认证框架。
diff --git a/IV. Spring Boot features/28.3.1 Client.md b/IV. Spring Boot features/28.3.1 Client.md
index 2a5a6380..dd61ce2d 100644
--- a/IV. Spring Boot features/28.3.1 Client.md
+++ b/IV. Spring Boot features/28.3.1 Client.md
@@ -1,30 +1,60 @@
### 28.3.1 客户端
-为了将web-app放入一个OAuth2客户端,你只需注解`@EnableOAuth2Client`,Spring Boot会创建`OAuth2ClientContext`和`OAuth2ProtectedResourceDetails`,这些是创建`OAuth2RestOperations`必需的。Spring Boot不会自动创建该bean,但你自己创建也不费力:
+如果你的类路径上有`spring-security-oauth2-client`,你可以利用某些自动配置更容易地设置OAuth2客户端。 这个配置使用`OAuth2ClientProperties`里的属性。
+
+你可以在`spring.security.oauth2.client`前缀下,注册多个OAuth2客户端和提供商,如下所示:
+
+```properties
+spring.security.oauth2.client.registration.my-client-1.client-id=abcd
+spring.security.oauth2.client.registration.my-client-1.client-secret=password
+spring.security.oauth2.client.registration.my-client-1.client-name=Client for user scope
+spring.security.oauth2.client.registration.my-client-1.provider=my-oauth-provider
+spring.security.oauth2.client.registration.my-client-1.scope=user
+spring.security.oauth2.client.registration.my-client-1.redirect-uri-template=http://my-redirect-uri.com
+spring.security.oauth2.client.registration.my-client-1.client-authentication-method=basic
+spring.security.oauth2.client.registration.my-client-1.authorization-grant-type=authorization_code
+
+spring.security.oauth2.client.registration.my-client-2.client-id=abcd
+spring.security.oauth2.client.registration.my-client-2.client-secret=password
+spring.security.oauth2.client.registration.my-client-2.client-name=Client for email scope
+spring.security.oauth2.client.registration.my-client-2.provider=my-oauth-provider
+spring.security.oauth2.client.registration.my-client-2.scope=email
+spring.security.oauth2.client.registration.my-client-2.redirect-uri-template=http://my-redirect-uri.com
+spring.security.oauth2.client.registration.my-client-2.client-authentication-method=basic
+spring.security.oauth2.client.registration.my-client-2.authorization-grant-type=authorization_code
+
+spring.security.oauth2.client.provider.my-oauth-provider.authorization-uri=http://my-auth-server/oauth/authorize
+spring.security.oauth2.client.provider.my-oauth-provider.token-uri=http://my-auth-server/oauth/token
+spring.security.oauth2.client.provider.my-oauth-provider.user-info-uri=http://my-auth-server/userinfo
+spring.security.oauth2.client.provider.my-oauth-provider.jwk-set-uri=http://my-auth-server/token_keys
+spring.security.oauth2.client.provider.my-oauth-provider.user-name-attribute=name
+```
+默认的,Spring Security的`OAuth2LoginAuthenticationFilter`只处理匹配`/login/oauth2/code/*`的URL。如果你想要自定义`redirect-uri-template`来使用不同的模式,你需要提供处理那个自定义模式的配置。比如,你可以添加类似于下面示例的你自己的`WebSecurityConfigurerAdapter`:
```java
-@Bean
-public OAuth2RestTemplate oauth2RestTemplate(OAuth2ClientContext oauth2ClientContext,
- OAuth2ProtectedResourceDetails details) {
- return new OAuth2RestTemplate(details, oauth2ClientContext);
+public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http
+ .authorizeRequests()
+ .anyRequest().authenticated()
+ .and()
+ .oauth2Login()
+ .redirectionEndpoint()
+ .baseUri("/custom-callback");
+ }
}
```
-**注** 你可能想添加一个限定名(qualifier),因为应用中可能定义多个`RestTemplate`。
-
-该配置使用`security.oauth2.client.*`作为证书(跟授权服务器使用的相同),此外,它也需要知道授权服务器中认证和token的URIs,例如:
-```yml
-security:
- oauth2:
- client:
- clientId: bd1c0a783ccdd1c9b9e4
- clientSecret: 1a9030fbca47a5b2c28e92f19050bb77824b5ad1
- accessTokenUri: https://github.com/login/oauth/access_token
- userAuthorizationUri: https://github.com/login/oauth/authorize
- clientAuthenticationScheme: form
-```
-具有该配置的应用在使用`OAuth2RestTemplate`时会重定向到GitHub以完成授权,如果已经登陆GitHub,你甚至不会注意到它已经授权过了。那些特殊的凭证(credentials)只在应用运行于8080端口时有效(为了更灵活,在GitHub或其他提供商上注册自己的客户端app)。
+对于通常的OAuth2和OpenID提供商,包括Google、Github、Facebook、和Okta,我们提供了一系列默认的提供商(`google`、`github`、`facebook`、`okta`)。
-在客户端获取access token时,你可以设置`security.oauth2.client.scope`(逗号分隔或一个YAML数组)来限制它请求的作用域(scope)。作用域默认是空的,默认值取决于授权服务器,通常依赖于它拥有的客户端在注册时的设置。
+如果你不需要自定义这些提供商,你可以把`provider`属性设置为其中的一个。同样的,如果你客户端的ID匹配默认支持的提供商,Spring Boot也会推断你要使用它。
-**注** 对`security.oauth2.client.client-authentication-scheme`也有设置,默认为"header"(如果你的OAuth2提供商不喜欢header认证,例如Github,你可能需要将它设置为“form”)。实际上,`security.oauth2.client.*`属性绑定到一个`AuthorizationCodeResourceDetails`实例,所以它的所有属性都可以指定。
+也就是说,下面例子中的两个配置使用Google提供商:
+```properties
+spring.security.oauth2.client.registration.my-client.client-id=abcd
+spring.security.oauth2.client.registration.my-client.client-secret=password
+spring.security.oauth2.client.registration.my-client.provider=google
-**注** 在一个非web应用中,你仍旧可以创建一个`OAuth2RestOperations`,并且跟`security.oauth2.client.*`配置关联。在这种情况下,它是一个“client credentials token grant”,如果你使用它的话就需要获取(此处不需要注解`@EnableOAuth2Client`或`@EnableOAuth2Sso`)。为了防止基础设施定义,只需要将`security.oauth2.client.client-id`从配置中移除(或将它设为空字符串)。
+spring.security.oauth2.client.registration.google.client-id=abcd
+spring.security.oauth2.client.registration.google.client-secret=password
+```
diff --git a/IV. Spring Boot features/28.3.2 Single Sign On.md b/IV. Spring Boot features/28.3.2 Single Sign On.md
deleted file mode 100644
index d327309c..00000000
--- a/IV. Spring Boot features/28.3.2 Single Sign On.md
+++ /dev/null
@@ -1,29 +0,0 @@
-### 28.3.2 单点登陆
-OAuth2客户端可用于从提供商抓取用户详情,然后转换为Spring Security需要的`Authentication` token。上述提到的资源服务器通过`user-info-uri`属性来支持该功能,这是基于OAuth2的单点登陆(SSO)协议最基本的,Spring Boot提供的`@EnableOAuth2Sso`注解让它更容易实践。通过添加该注解及端点配置(`security.oauth2.client.*`),Github客户端就可以使用`/user/`端点保护它的所有资源了:
-```yaml
-security:
- oauth2:
-...
- resource:
- userInfoUri: https://api.github.com/user
- preferTokenInfo: false
-```
-由于所有路径默认都处于保护下,也就没有主页展示那些未授权的用户,进而邀请他们去登陆(通过访问`/login`路径,或`security.oauth2.sso.login-path`指定的路径)。
-
-为了自定义访问规则或保护的路径(这样你就可以添加主页),你可以将`@EnableOAuth2Sso`添加到一个`WebSecurityConfigurerAdapter`,该注解会包装它,增强需要的地方以使`/login`路径工作。例如,这里我们允许未授权的用户访问主页`/`,其他的依旧保持默认:
-```java
-@Configuration
-static class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
-
- @Override
- public void init(WebSecurity web) {
- web.ignore.antMatchers("/");
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.antMatcher("/**").authorizeRequests().anyRequest().authenticated();
- }
-
-}
-```
diff --git a/IV. Spring Boot features/28.4 Actuator Security.md b/IV. Spring Boot features/28.4 Actuator Security.md
index 790592be..343caa12 100644
--- a/IV. Spring Boot features/28.4 Actuator Security.md
+++ b/IV. Spring Boot features/28.4 Actuator Security.md
@@ -1,10 +1,7 @@
-### 28.4 Actuator安全
-如果Actuator处于使用中,你会发现:
+### 28.4 执行器安全
-* 管理的端点是安全的,即使应用端点不安全。
-* Security事件转换为`AuditEvent`实例,并发布到`AuditEventRepository`。
-* 默认用户拥有`ACTUATOR`和`USER`角色。
-
-Actuator的安全特性可以通过外部配置属性(`management.security.*`)进行修改。为了覆盖应用访问规则但不覆盖actuator的访问规则,你可以添加一个`WebSecurityConfigurerAdapter`类型的`@Bean`,并注解`@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)`,如果想覆盖actuator访问规则,则注解`@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER)`。
+为了安全,`/health`与`/info`之外的所有执行器都默认禁用。可以使用`management.endpoints.web.exposure.include`属性启用执行器。
+如果Spring Security在类路径上,并且没有其它的`WebSecurityConfigurerAdapter`,执行器会受到Spring Boot自动配置的保护。如果你自定义了一个`WebSecurityConfigurerAdapter`,Spring Boot将不会自动配置,你将完全掌控执行器的访问规则。
+**注** 在设置`management.endpoints.web.exposure.include`之前,确保暴露的执行器不包含敏感信息,并且/或者将它们放在防火墙后面,或是通过Spring Security等进行保护。
\ No newline at end of file
diff --git a/IV. Spring Boot features/28.4.1 Cross Site Request Forgery Protection.md b/IV. Spring Boot features/28.4.1 Cross Site Request Forgery Protection.md
new file mode 100644
index 00000000..f2dd46b9
--- /dev/null
+++ b/IV. Spring Boot features/28.4.1 Cross Site Request Forgery Protection.md
@@ -0,0 +1,7 @@
+### 28.4.1 跨站请求伪造保护
+
+由于Spring Boot依赖Spring Security的默认配置,CSRF保护默认启用。这意味着:当默认安全配置在使用中时,需要`POST`(关机和记录器端点)、`PUT`或者`DELETE`的执行器端点会得到一个403的禁止错误。
+
+**注** 我们推荐只在创建由非浏览器客户端使用的服务时,完全禁用CSRF保护。
+
+可以在[Spring Security参考指南](https://docs.spring.io/spring-security/site/docs/5.0.3.RELEASE/reference/htmlsingle#csrf)查看与CSRF保护相关的额外信息。
\ No newline at end of file
diff --git a/IV. Spring Boot features/29. Working with SQL Databases.md b/IV. Spring Boot features/29. Working with SQL Databases.md
new file mode 100644
index 00000000..e963d3d1
--- /dev/null
+++ b/IV. Spring Boot features/29. Working with SQL Databases.md
@@ -0,0 +1,3 @@
+### 29. 使用SQL数据库
+
+Spring框架为使用SQL数据库提供了广泛支持,从使用`JdbcTemplate`直接访问JDBC到完全的“对象关系映射”技术,比如Hibernate。Spring Data提供了更高级的功能:直接从接口创建`Repository`实现,并根据约定从方法名生成查询。
diff --git a/IV. Spring Boot features/29. Working with SQL databases.md b/IV. Spring Boot features/29. Working with SQL databases.md
deleted file mode 100644
index eeaed696..00000000
--- a/IV. Spring Boot features/29. Working with SQL databases.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 29. 使用SQL数据库
-
-Spring框架为使用SQL数据库提供了广泛支持,从使用`JdbcTemplate`直接访问JDBC到完全的‘对象关系映射’技术,比如Hibernate。Spring Data提供了更高级的功能,直接从接口创建`Repository`实现,并根据约定从方法名生成查询。
diff --git a/IV. Spring Boot features/29.1. Configure a DataSource.md b/IV. Spring Boot features/29.1. Configure a DataSource.md
index fd3be78d..0a028706 100644
--- a/IV. Spring Boot features/29.1. Configure a DataSource.md
+++ b/IV. Spring Boot features/29.1. Configure a DataSource.md
@@ -1,5 +1,5 @@
-### 29.1. 配置DataSource
-
-Java的`javax.sql.DataSource`接口提供了一个标准的使用数据库连接的方法。通常,DataSource使用`URL`和相应的凭证去初始化数据库连接。
-
-**提示** 查看How-to章节,获取更多的高级示例,典型地完全控制DataSource的配置。
+### 29.1. 配置数据源
+
+Java的`javax.sql.DataSource`接口提供了一个标准的使用数据库连接的方法。通常,DataSource使用`URL`和相应的凭证去初始化数据库连接。
+
+**提示** 查看[How-to章节](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-configure-a-datasource),获取更多的高级示例,典型地完全控制DataSource的配置。
diff --git a/IV. Spring Boot features/29.1.1. Embedded Database Support.md b/IV. Spring Boot features/29.1.1. Embedded Database Support.md
index 82fff2f8..7938a5ee 100644
--- a/IV. Spring Boot features/29.1.1. Embedded Database Support.md
+++ b/IV. Spring Boot features/29.1.1. Embedded Database Support.md
@@ -2,14 +2,14 @@
开发应用时使用内存数据库是很方便的。显然,内存数据库不提供持久化存储;你只需要在应用启动时填充数据库,在应用结束前预先清除数据。
-**提示** How-to章节包含有一章讲解如何初始化数据库。
+**提示** How-to章节包含有[一章讲解如何初始化数据库](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-database-initialization)。
-Spring Boot可以自动配置的内嵌数据库包括[H2](http://www.h2database.com/), [HSQL](http://hsqldb.org/)和[Derby](http://db.apache.org/derby/)。你不需要提供任何连接URLs,只需要添加你想使用的内嵌数据库依赖。
+Spring Boot可以自动配置的内嵌数据库包括[H2](http://www.h2database.com/), [HSQL](http://hsqldb.org/)和[Derby](https://db.apache.org/derby/)。你不需要提供任何连接URL,只需要添加你想使用的内嵌数据库依赖。
**注** 如果你正在你的测试中使用这个特性,你可能注意到了:不管你使用了多少应用上下文,你的整个测试套件重复使用了同一个数据库。如果你想要确保每个上下文各自有一个内嵌数据库,你应当把
`spring.datasource.generate-unique-name`设置为`true`。
-示例:典型的POM依赖如下:
+例如,典型的POM依赖如下所示:
```xml
org.springframework.boot
diff --git a/IV. Spring Boot features/29.1.2. Connection to a Production Database.md b/IV. Spring Boot features/29.1.2. Connection to a Production Database.md
new file mode 100644
index 00000000..2d3038ff
--- /dev/null
+++ b/IV. Spring Boot features/29.1.2. Connection to a Production Database.md
@@ -0,0 +1,40 @@
+### 29.1.2 连接生产环境数据库
+
+生产环境的数据库连接可以通过池化的`DataSource`进行自动配置。Spring Boot使用如下的算法,选取特定实现:
+
+1. 出于[HikariCP](https://github.com/brettwooldridge/HikariCP)的优秀性能和并发,如果可用总会优先使用它。
+2. 如果tomcat数据源连接池可用,我们将使用它。
+3. 如果HikariCP和tomcat数据源连接池都不能用。如果[Commons DBCP2](https://commons.apache.org/proper/commons-dbcp/)可用,我们将使用它。
+
+如果使用`spring-boot-starter-jdbc`或`spring-boot-starter-data-jpa`“starters”,你会自动添加`HikariCP`依赖。
+
+**注** 通过指定`spring.datasource.type`属性,你可以完全抛弃该算法,然后指定数据库连接池。如果你在tomcat容器中运行应用,由于默认提供`tomcat-jdbc`,这就很重要了。
+
+**注** 其他的连接池可以手动配置,如果你定义自己的`DataSource` bean,自动配置是不会发生的。
+
+DataSource配置被外部的`spring.datasource.*`属性控制,例如,你可能会在`application.properties`中声明以下片段:
+```java
+spring.datasource.url=jdbc:mysql://localhost/test
+spring.datasource.username=dbuser
+spring.datasource.password=dbpass
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
+```
+**注** 你应该至少使用`spring.datasource.url`属性指定url,或Spring Boot尝试自动配置内嵌数据库。
+
+**注** 你经常不需要指定`driver-class-name`,因为Spring boot可以从`url`推断大部分数据库。
+
+**注** 对于将要创建的池化`DataSource`,我们需要验证是否有一个可用的`Driver`,所以在做其他事前会校验它。也就是说,如果你设置`spring.datasource.driver-class-name=com.mysql.jdbc.Driver`,然后该class加载出来,否则就会出错。
+
+其他可选配置可以查看[DataSourceProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java),有些标准配置是跟实现无关的,对于实现相关的配置可以通过相应前缀进行设置(`spring.datasource.hikari.*`,`spring.datasource.tomcat.*`和`spring.datasource.dbcp2.*`),具体参考你使用的连接池文档。
+
+例如,如果正在使用[Tomcat连接池](https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html#Common_Attributes),你可以自定义很多其他设置,如下所示:
+```properties
+# Number of ms to wait before throwing an exception if no connection is available.
+spring.datasource.tomcat.max-wait=10000
+
+# Maximum number of active connections that can be allocated from this pool at the same time.
+spring.datasource.tomcat.max-active=50
+
+# Validate the connection before borrowing it from the pool.
+spring.datasource.tomcat.test-on-borrow=true
+```
diff --git a/IV. Spring Boot features/29.1.2. Connection to a production database.md b/IV. Spring Boot features/29.1.2. Connection to a production database.md
deleted file mode 100644
index acd51898..00000000
--- a/IV. Spring Boot features/29.1.2. Connection to a production database.md
+++ /dev/null
@@ -1,40 +0,0 @@
-### 29.1.2. 连接生产环境数据库
-
-生产环境的数据库连接可以通过池化的`DataSource`进行自动配置,下面是选取特定实现的算法:
-
-- 出于HikariCP的优秀性能和并发,如果可用总会优先使用它。
-- 如果tomcat数据源连接池可用,我们将使用它。
-- 如果HikariCP和tomcat数据源连接池都不能用。如果Commons DBCP2可用,我们将使用它。
-
-如果使用`spring-boot-starter-jdbc`或`spring-boot-starter-data-jpa` 'starters',你会自动添加`HikariCP`依赖。
-
-**注** 通过指定`spring.datasource.type`属性,你可以完全抛弃该算法,然后指定数据库连接池。如果你在tomcat容器中运行应用,由于默认提供`tomcat-jdbc`,这就很重要了。
-
-**注** 其他的连接池可以手动配置,如果你定义自己的`DataSource` bean,自动配置是不会发生的。
-
-DataSource配置被外部的`spring.datasource.*`属性控制,例如,你可能会在`application.properties`中声明以下片段:
-```java
-spring.datasource.url=jdbc:mysql://localhost/test
-spring.datasource.username=dbuser
-spring.datasource.password=dbpass
-spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-```
-**注** 你应该至少使用`spring.datasource.url`属性指定url,或Spring Boot尝试自动配置内嵌数据库。
-
-**注** 你经常不需要指定`driver-class-name`,因为Spring boot可以从`url`推断大部分数据库。
-
-**注** 对于将要创建的池化`DataSource`,我们需要验证是否有一个可用的`Driver`,所以在做其他事前会校验它。比如,如果你设置`spring.datasource.driver-class-name=com.mysql.jdbc.Driver`,然后该class加载出来,否则就会出错。
-
-其他可选配置可以查看[DataSourceProperties](https://github.com/spring-projects/spring-boot/tree/v2.0.0.M5/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java),有些标准配置是跟实现无关的,对于实现相关的配置可以通过相应前缀进行设置(`spring.datasource.hikari.*`,`spring.datasource.tomcat.*`和`spring.datasource.dbcp2.*`),具体参考你使用的连接池文档。
-
-例如,如果正在使用[Tomcat连接池](http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html#Common_Attributes),你可以自定义很多其他设置:
-```properties
-# Number of ms to wait before throwing an exception if no connection is available.
-spring.datasource.tomcat.max-wait=10000
-
-# Maximum number of active connections that can be allocated from this pool at the same time.
-spring.datasource.tomcat.max-active=50
-
-# Validate the connection before borrowing it from the pool.
-spring.datasource.tomcat.test-on-borrow=true
-```
diff --git a/IV. Spring Boot features/29.1.3. Connection to a JNDI DataSource.md b/IV. Spring Boot features/29.1.3. Connection to a JNDI DataSource.md
index 044fc32a..e1d6a4b2 100644
--- a/IV. Spring Boot features/29.1.3. Connection to a JNDI DataSource.md
+++ b/IV. Spring Boot features/29.1.3. Connection to a JNDI DataSource.md
@@ -2,7 +2,7 @@
如果正在将Spring Boot应用部署到一个应用服务器,你可能想要用应用服务器内建的特性来配置和管理你的DataSource,并使用JNDI访问它。
-`spring.datasource.jndi-name`属性可用来替代`spring.datasource.url`,`spring.datasource.username`和`spring.datasource.password`去从一个特定的JNDI路径获取`DataSource`,比如,以下`application.properties`中的片段展示了如何获取JBoss AS定义的`DataSource`:
+`spring.datasource.jndi-name`属性可用来替代`spring.datasource.url`、`spring.datasource.username`和`spring.datasource.password`,去从一个特定的JNDI路径获取`DataSource`。比如,以下`application.properties`中的片段展示了如何获取JBoss AS定义的`DataSource`:
```java
spring.datasource.jndi-name=java:jboss/datasources/customers
```
diff --git a/IV. Spring Boot features/29.2. Using JdbcTemplate.md b/IV. Spring Boot features/29.2. Using JdbcTemplate.md
index 1f3b7b78..3241fecd 100644
--- a/IV. Spring Boot features/29.2. Using JdbcTemplate.md
+++ b/IV. Spring Boot features/29.2. Using JdbcTemplate.md
@@ -1,6 +1,6 @@
### 29.2. 使用JdbcTemplate
-Spring的`JdbcTemplate`和`NamedParameterJdbcTemplate`类会被自动配置,你可以将它们直接`@Autowire`到自己的beans:
+Spring的`JdbcTemplate`和`NamedParameterJdbcTemplate`类会被自动配置,你可以将它们直接`@Autowire`到自己的bean,如下所示:
```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -19,9 +19,9 @@ public class MyBean {
}
```
-你可以使用`spring.jdbc.template.*`属性自定义模版的一些属性:
+你可以使用`spring.jdbc.template.*`属性自定义模版的一些属性,如下所示:
```properties
spring.jdbc.template.max-rows=500
```
-**提示** `NamedParameterJdbcTemplate`在幕后重复使用了同一个`JdbcTemplate`实例。如果定义了不止一个`JdbcTemplate`,而且不存在候选,`NamedParameterJdbcTemplate`就没有被自动配置。
\ No newline at end of file
+**提示** `NamedParameterJdbcTemplate`在幕后重复使用了同一个`JdbcTemplate`实例。如果定义了不止一个`JdbcTemplate`,而且不存在候选,`NamedParameterJdbcTemplate`就没有被自动配置。
diff --git a/IV. Spring Boot features/29.3. JPA and Spring Data.md b/IV. Spring Boot features/29.3. JPA and Spring Data.md
new file mode 100644
index 00000000..33132666
--- /dev/null
+++ b/IV. Spring Boot features/29.3. JPA and Spring Data.md
@@ -0,0 +1,9 @@
+### 29.3. JPA和Spring Data
+
+Java持久化API是一个让你将对象映射为关系数据库的标准技术。`spring-boot-starter-data-jpa` POM提供了一种快速上手的方式,它提供以下关键依赖:
+
+- Hibernate:一个非常流行的JPA实现。
+- Spring Data JPA:让实现基于JPA的repositories更容易。
+- Spring ORMs:Spring框架支持的核心ORM。
+
+**注** 我们不想在这涉及太多关于JPA或[Spring Data](https://projects.spring.io/spring-data/)的细节。你可以参考来自[spring.io](https://spring.io/)的指南[使用JPA获取数据](https://spring.io/guides/gs/accessing-data-jpa/),并阅读[Spring Data JPA](https://projects.spring.io/spring-data-jpa/)和[Hibernate](https://hibernate.org/orm/documentation/)的参考文档。
diff --git "a/IV. Spring Boot features/29.3. JPA and \342\200\230Spring Data\342\200\231.md" "b/IV. Spring Boot features/29.3. JPA and \342\200\230Spring Data\342\200\231.md"
deleted file mode 100644
index 9068e841..00000000
--- "a/IV. Spring Boot features/29.3. JPA and \342\200\230Spring Data\342\200\231.md"
+++ /dev/null
@@ -1,9 +0,0 @@
-### 29.3. JPA和Spring Data
-
-Java持久化API是一个允许你将对象映射为关系数据库的标准技术,`spring-boot-starter-data-jpa` POM提供了一种快速上手的方式,它提供以下关键依赖:
-
-- Hibernate - 一个非常流行的JPA实现。
-- Spring Data JPA - 让实现基于JPA的repositories更容易。
-- Spring ORMs - Spring框架支持的核心ORM。
-
-**注** 我们不想在这涉及太多关于JPA或Spring Data的细节。你可以参考来自[spring.io](http://spring.io/)的指南[使用JPA获取数据](http://spring.io/guides/gs/accessing-data-jpa/),并阅读[Spring Data JPA](http://projects.spring.io/spring-data-jpa/)和[Hibernate](http://hibernate.org/orm/documentation/)的参考文档。
diff --git a/IV. Spring Boot features/29.3.1. Entity Classes.md b/IV. Spring Boot features/29.3.1. Entity Classes.md
index 6b8e6e15..14de5f88 100644
--- a/IV. Spring Boot features/29.3.1. Entity Classes.md
+++ b/IV. Spring Boot features/29.3.1. Entity Classes.md
@@ -1,8 +1,8 @@
### 29.3.1. 实体类
-通常,JPA实体类被定义到一个`persistence.xml`文件,在Spring Boot中,这个文件被'实体扫描'取代。默认情况,Spring Boot会查找主配置类(被`@EnableAutoConfiguration`或`@SpringBootApplication`注解的类)下的所有包。
+通常,JPA实体类被定义到一个`persistence.xml`文件。在Spring Boot中,这个文件被“实体扫描”取代。默认的,Spring Boot会查找主配置类(被`@EnableAutoConfiguration`或`@SpringBootApplication`注解的类)下的所有包。
-任何被`@Entity`,`@Embeddable`或`@MappedSuperclass`注解的类都将被考虑,一个普通的实体类看起来像这样:
+任何被`@Entity`,`@Embeddable`或`@MappedSuperclass`注解的类都将被考虑。一个普通的实体类看起来像这样:
```java
package com.example.myapp.domain;
@@ -44,4 +44,4 @@ public class City implements Serializable {
// ... etc
}
```
-**注** 你可以使用`@EntityScan`注解自定义实体扫描路径,具体参考[章节 78.4,从Spring配置分离`@Entity`定义](../IX. ‘How-to’ guides/78.4. Separate @Entity definitions from Spring configuration.md)。
+**注** 你可以使用`@EntityScan`注解自定义实体扫描路径,具体参考[章节 79.4,从Spring配置分离`@Entity`定义](../IX. ‘How-to’ guides/79.4. Separate @Entity Definitions from Spring Configuration.md)。
diff --git a/IV. Spring Boot features/29.3.2. Spring Data JPA Repositories.md b/IV. Spring Boot features/29.3.2. Spring Data JPA Repositories.md
index ca0267d2..f9dbb971 100644
--- a/IV. Spring Boot features/29.3.2. Spring Data JPA Repositories.md
+++ b/IV. Spring Boot features/29.3.2. Spring Data JPA Repositories.md
@@ -1,12 +1,12 @@
### 29.3.2. Spring Data JPA仓库
-Spring Data JPA仓库(repositories)是用来定义访问数据的接口。根据你的方法名,JPA查询会被自动创建,比如,一个`CityRepository`接口可能声明一个`findAllByState(String state)`方法,用来查找给定状态的所有城市。
+[Spring Data JPA](http://projects.spring.io/spring-data-jpa/)仓库是用来定义访问数据的接口。根据你的方法名,JPA查询会被自动创建,比如,一个`CityRepository`接口可能声明一个`findAllByState(String state)`方法,用来查找给定状态的所有城市。
-对于比较复杂的查询,你可以使用Spring Data的[`Query`](http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/Query.html)注解你的方法。
+对于比较复杂的查询,你可以使用Spring Data的[`Query`](https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/Query.html)注解你的方法。
-Spring Data仓库通常继承自[`Repository`](http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/Repository.html)或[`CrudRepository`](http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html)接口。如果你使用自动配置,Spring Boot会搜索主配置类(注解`@EnableAutoConfiguration`或`@SpringBootApplication`的类)所在包下的仓库。
+Spring Data仓库通常继承自[`Repository`](https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/Repository.html)或[`CrudRepository`](https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html)接口。如果你使用自动配置,Spring Boot会搜索主配置类(注解`@EnableAutoConfiguration`或`@SpringBootApplication`的类)所在包下的仓库。
-下面是典型的Spring Data仓库:
+下面是典型的Spring Data仓库接口定义:
```java
package com.example.myapp.domain;
@@ -20,4 +20,4 @@ public interface CityRepository extends Repository {
City findByNameAndCountryAllIgnoringCase(String name, String country);
}
```
-**注**:我们仅仅触及了Spring Data JPA的表面,具体查看它的[参考指南](http://projects.spring.io/spring-data-jpa/)。
+**注**:我们仅仅触及了Spring Data JPA的表面,具体查看它的[参考指南](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/)。
diff --git a/IV. Spring Boot features/29.3.3. Creating and Dropping JPA Databases.md b/IV. Spring Boot features/29.3.3. Creating and Dropping JPA Databases.md
new file mode 100644
index 00000000..518fa928
--- /dev/null
+++ b/IV. Spring Boot features/29.3.3. Creating and Dropping JPA Databases.md
@@ -0,0 +1,13 @@
+### 29.3.3. 创建和删除JPA数据库
+
+默认情况下,只有在你使用内嵌数据库(H2, HSQL或Derby)时,JPA数据库才会被自动创建。你可以使用`spring.jpa.*`属性显式的设置JPA,比如,将以下配置添加到`application.properties`中可以创建和删除表:
+```properties
+spring.jpa.hibernate.ddl-auto=create-drop
+```
+**注** Hibernate自己内部对创建,删除表支持的属性是`hibernate.hbm2ddl.auto`(如果你记得更好)。你可以使用`spring.jpa.properties.*`设置Hibernate其他的native属性(前缀在被添加到实体管理器之前会被去掉)。下面是给Hibernate设置JPA属性的例子:
+```properties
+`spring.jpa.properties.hibernate.globally_quoted_identifiers=true`
+```
+上面的例子将`true`传递到Hibernate实体管理器里的`hibernate.globally_quoted_identifiers`属性。
+
+通常,DDL执行(或验证)被延迟到`ApplicationContext`启动后,这可以通过`spring.jpa.generate-ddl`标签控制,如果Hibernate自动配置被激活,那该标识就不会被使用,因为`ddl-auto`设置粒度更细。
diff --git a/IV. Spring Boot features/29.3.3. Creating and dropping JPA databases.md b/IV. Spring Boot features/29.3.3. Creating and dropping JPA databases.md
deleted file mode 100644
index b84c847f..00000000
--- a/IV. Spring Boot features/29.3.3. Creating and dropping JPA databases.md
+++ /dev/null
@@ -1,9 +0,0 @@
-### 29.3.3. 创建和删除JPA数据库
-
-默认情况下,只有在你使用内嵌数据库(H2, HSQL或Derby)时,JPA数据库才会被自动创建。你可以使用`spring.jpa.*`属性显式的设置JPA,比如,将以下配置添加到`application.properties`中可以创建和删除表:
-```properties
-spring.jpa.hibernate.ddl-auto=create-drop
-```
-**注** Hibernate自己内部对创建,删除表支持的属性是`hibernate.hbm2ddl.auto`(如果你记得更好)。你可以使用`spring.jpa.properties.*`(前缀在被添加到实体管理器之前会被去掉)设置Hibernate其他的native属性,比如:`spring.jpa.properties.hibernate.globally_quoted_identifiers=true`将传递`hibernate.globally_quoted_identifiers`到Hibernate实体管理器。
-
-通常,DDL执行(或验证)被延迟到`ApplicationContext`启动后,这可以通过`spring.jpa.generate-ddl`标签控制,如果Hibernate自动配置被激活,那该标识就不会被使用,因为`ddl-auto`设置粒度更细。
diff --git "a/IV. Spring Boot features/29.4 Using H2\342\200\231s Web Console.md" "b/IV. Spring Boot features/29.4 Using H2\342\200\231s Web Console.md"
new file mode 100644
index 00000000..fa69d98c
--- /dev/null
+++ "b/IV. Spring Boot features/29.4 Using H2\342\200\231s Web Console.md"
@@ -0,0 +1,9 @@
+### 29.4 使用H2的web控制台
+
+[H2数据库](http://www.h2database.com/)提供一个[基于浏览器的控制台](http://www.h2database.com/html/quickstart.html#h2_console),Spring Boot可以为你自动配置。如果以下条件满足,则控制台会被自动配置:
+
+* 你正在开发一个web应用。
+* 添加`com.h2database:h2`依赖。
+* 你正在使用[Spring Boot开发者工具](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#using-boot-devtools)。
+
+**注** 如果你没有使用Spring Boot的开发者工具,仍想利用H2的控制台,可以设置`spring.h2.console.enabled`属性值为`true`。H2控制台应该只用于开发期间,所以确保生产环境没有设置`spring.h2.console.enabled`。
diff --git "a/IV. Spring Boot features/29.4 Using H2\342\200\231s web console.md" "b/IV. Spring Boot features/29.4 Using H2\342\200\231s web console.md"
deleted file mode 100644
index bf050249..00000000
--- "a/IV. Spring Boot features/29.4 Using H2\342\200\231s web console.md"
+++ /dev/null
@@ -1,8 +0,0 @@
-### 29.4 使用H2的web控制台
-[H2数据库](http://www.h2database.com/)提供一个[基于浏览器的控制台](http://www.h2database.com/html/quickstart.html#h2_console),Spring Boot可以为你自动配置。如果以下条件满足,则控制台会被自动配置:
-
-* 你正在开发一个web应用。
-* 添加`com.h2database:h2`依赖。
-* 你正在使用[Spring Boot开发者工具](http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#using-boot-devtools)。
-
-**注** 如果你没有使用Spring Boot的开发者工具,仍想利用H2的控制台,可以设置`spring.h2.console.enabled`属性值为`true`。H2控制台应该只用于开发期间,所以确保生产环境没有设置`spring.h2.console.enabled`。
diff --git "a/IV. Spring Boot features/29.4.1 Changing the H2 Console\342\200\231s Path.md" "b/IV. Spring Boot features/29.4.1 Changing the H2 Console\342\200\231s Path.md"
new file mode 100644
index 00000000..94b2a350
--- /dev/null
+++ "b/IV. Spring Boot features/29.4.1 Changing the H2 Console\342\200\231s Path.md"
@@ -0,0 +1,3 @@
+### 29.4.1 改变H2控制台路径
+
+H2控制台路径默认为`/h2-console`,你可以通过设置`spring.h2.console.path`属性自定义该路径。
diff --git "a/IV. Spring Boot features/29.4.1 Changing the H2 console\342\200\231s path.md" "b/IV. Spring Boot features/29.4.1 Changing the H2 console\342\200\231s path.md"
deleted file mode 100644
index 80a31dc7..00000000
--- "a/IV. Spring Boot features/29.4.1 Changing the H2 console\342\200\231s path.md"
+++ /dev/null
@@ -1,2 +0,0 @@
-### 29.4.1 改变H2控制台路径
-H2控制台路径默认为`/h2-console`,你可以通过设置`spring.h2.console.path`属性自定义该路径。
diff --git a/IV. Spring Boot features/29.4.2 Securing the H2 console.md b/IV. Spring Boot features/29.4.2 Securing the H2 console.md
deleted file mode 100644
index 3a044d41..00000000
--- a/IV. Spring Boot features/29.4.2 Securing the H2 console.md
+++ /dev/null
@@ -1,6 +0,0 @@
-### 29.4.2 保护H2控制台
-当添加Spring Security依赖,并且启用基本认证时,Spring Boot自动使用基本认证保护H2控制台。以下属性可用于自定义安全配置:
-
-* `security.user.role`
-* `security.basic.authorize-mode`
-* `security.basic.enabled`
diff --git a/IV. Spring Boot features/29.5.2 Using DSLContext.md b/IV. Spring Boot features/29.5.2 Using DSLContext.md
index 48b56696..1fcdb242 100644
--- a/IV. Spring Boot features/29.5.2 Using DSLContext.md
+++ b/IV. Spring Boot features/29.5.2 Using DSLContext.md
@@ -1,4 +1,5 @@
### 29.5.2 使用DSLContext
+
jOOQ提供的流式(fluent)API是通过`org.jooq.DSLContext`接口初始化的,Spring Boot将自动配置一个`DSLContext`为Spring Bean,并将它跟应用的`DataSource`连接起来。想要使用`DSLContext`,只需`@Autowire`注入它:
```java
@Component
@@ -13,9 +14,9 @@ public class JooqExample implements CommandLineRunner {
}
```
-**注** jOOQ手册倾向于使用一个名为`create`的变量持有`DSLContext`,示例中也是这样做的。
+**注** jOOQ手册倾向于使用一个名为`create`的变量持有`DSLContext`。
-然后你就可以使用`DSLContext`构造查询:
+然后你就可以使用`DSLContext`构造查询,如下所示:
```java
public List authorsBornAfter1980() {
return this.create.selectFrom(AUTHOR)
diff --git a/IV. Spring Boot features/29.5.3 jOOQ SQL Dialect.md b/IV. Spring Boot features/29.5.3 jOOQ SQL Dialect.md
new file mode 100644
index 00000000..f6bb2626
--- /dev/null
+++ b/IV. Spring Boot features/29.5.3 jOOQ SQL Dialect.md
@@ -0,0 +1,5 @@
+### 29.5.3 jOOQ SQL方言
+
+Spring Boot决定了对你的数据库使用何种SQL方言,除非你配置了`spring.jooq.sql-dialect`属性。如果探测不到方言,将使用`默认值`。
+
+**注** Spring Boot只能自动配置jOOQ的开源版本支持的方言。
diff --git a/IV. Spring Boot features/29.5.3 jOOQ SQL dialect.md b/IV. Spring Boot features/29.5.3 jOOQ SQL dialect.md
deleted file mode 100644
index 132a02d9..00000000
--- a/IV. Spring Boot features/29.5.3 jOOQ SQL dialect.md
+++ /dev/null
@@ -1,4 +0,0 @@
-### 29.5.3 jOOQ SQL方言
-Spring Boot决定了对你的数据库使用何种SQL方言,除非你配置了`spring.jooq.sql-dialect`属性。如果探测不到方言,将使用`默认值`。
-
-**注** Spring Boot只能自动配置jOOQ的开源版本支持的方言。
diff --git a/IV. Spring Boot features/30. Working with NoSQL Technologies.md b/IV. Spring Boot features/30. Working with NoSQL Technologies.md
new file mode 100644
index 00000000..59ccbbd3
--- /dev/null
+++ b/IV. Spring Boot features/30. Working with NoSQL Technologies.md
@@ -0,0 +1,3 @@
+### 30. 使用NoSQL技术
+
+Spring Data提供其他项目,用来帮你使用各种各样的NoSQL技术,包括:[MongoDB](https://projects.spring.io/spring-data-mongodb/)、[Neo4J](https://projects.spring.io/spring-data-neo4j/)、[Elasticsearch](https://github.com/spring-projects/spring-data-elasticsearch/)、 [Solr](https://projects.spring.io/spring-data-solr/)、[Redis](https://projects.spring.io/spring-data-redis/)、 [Gemfire](https://projects.spring.io/spring-data-gemfire/)、[Cassandra](https://projects.spring.io/spring-data-cassandra/)、[Couchbase](https://projects.spring.io/spring-data-couchbase/)和[LDAP](https://projects.spring.io/spring-data-ldap/)。Spring Boot为Redis、MongoDB、Elasticsearch、Solr Cassandra、Couchbase和LDAP提供自动配置。你也可以充分利用其他项目,但需要自己配置它们,具体查看[projects.spring.io/spring-data](https://projects.spring.io/spring-data)中相应的参考文档。
diff --git a/IV. Spring Boot features/30. Working with NoSQL technologies.md b/IV. Spring Boot features/30. Working with NoSQL technologies.md
deleted file mode 100644
index 66ea61f6..00000000
--- a/IV. Spring Boot features/30. Working with NoSQL technologies.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 30. 使用NoSQL技术
-
-Spring Data提供其他项目,用来帮你使用各种各样的NoSQL技术,包括[MongoDB](http://projects.spring.io/spring-data-mongodb/), [Neo4J](http://projects.spring.io/spring-data-neo4j/), [Elasticsearch](https://github.com/spring-projects/spring-data-elasticsearch/), [Solr](http://projects.spring.io/spring-data-solr/), [Redis](http://projects.spring.io/spring-data-redis/), [Gemfire](http://projects.spring.io/spring-data-gemfire/), [Cassandra](http://projects.spring.io/spring-data-cassandra/),[Couchbase](http://projects.spring.io/spring-data-couchbase/)和[LDAP](http://projects.spring.io/spring-data-ldap/)。Spring Boot为Redis, MongoDB, Elasticsearch, Solr Cassandra,Couchbase和LDAP提供自动配置。你也可以充分利用其他项目,但需要自己配置它们,具体查看[projects.spring.io/spring-data](http://projects.spring.io/spring-data/)中相应的参考文档。
diff --git a/IV. Spring Boot features/30.1. Redis.md b/IV. Spring Boot features/30.1. Redis.md
index a3bee1fb..8e7634c6 100644
--- a/IV. Spring Boot features/30.1. Redis.md
+++ b/IV. Spring Boot features/30.1. Redis.md
@@ -1,4 +1,6 @@
### 30.1. Redis
-[Redis](http://redis.io/)是一个缓存,消息中间件及具有丰富特性的键值存储系统。Spring Boot为[Jedis](https://github.com/xetorthio/jedis/)和[Lettuce](https://github.com/mp911de/lettuce/)客户端library提供基本的自动配置,[Spring Data Redis](https://github.com/spring-projects/spring-data-redis)提供了在它之上的抽象。
-`spring-boot-starter-redis`'Starter'默认使用[Jedis](https://github.com/xetorthio/jedis/)方便地集合了需要的依赖。如果你正在搭建一个响应式的应用,`spring-boot-starter-data-redis-reactive`'Starter'对你来说非常有用。
+[Redis](http://redis.io/)是一个缓存、消息中间件及具有丰富特性的键值存储系统。Spring Boot为[Lettuce](https://github.com/lettuce-io/lettuce-core/)和[Jedis](https://github.com/xetorthio/jedis/)客户端库提供基本的自动配置。[Spring Data Redis](https://github.com/spring-projects/spring-data-redis)提供了在它们之上的抽象。
+`spring-boot-starter-redis`“Starter”方便地集合了需要的依赖。它默认使用[Lettuce](https://github.com/lettuce-io/lettuce-core/),既处理传统应用,也处理响应式应用。
+
+**注** 为了与其它存储系统保持一致,我们也提供了带有响应式支持的`spring-boot-starter-data-redis-reactive`“Starter”。
diff --git a/IV. Spring Boot features/30.1.1. Connecting to Redis.md b/IV. Spring Boot features/30.1.1. Connecting to Redis.md
index 1203abaf..67811d84 100644
--- a/IV. Spring Boot features/30.1.1. Connecting to Redis.md
+++ b/IV. Spring Boot features/30.1.1. Connecting to Redis.md
@@ -1,6 +1,6 @@
### 30.1.1. 连接Redis
-你可以注入一个自动配置的`RedisConnectionFactory`,`StringRedisTemplate`或普通的`RedisTemplate`实例,或任何其他Spring Bean只要你愿意。默认情况下,这个实例将尝试使用`localhost:6379`连接Redis服务器:
+你可以注入一个自动配置的`RedisConnectionFactory`,`StringRedisTemplate`或普通的`RedisTemplate`实例,或任何其他Spring Bean只要你愿意。默认情况下,这个实例将尝试使用`localhost:6379`连接Redis服务器。下面的列表展示了这样的bean的一个示例:
```java
@Component
public class MyBean {
@@ -15,6 +15,6 @@ public class MyBean {
}
```
-**提示** 为了实现更高级的定制,你也可以注册任意数量的实现了`JedisClientConfigurationBuilderCustomizer`的bean。如果你正在使用Lettuce,那就实现`JedisClientConfigurationBuilderCustomizer`。
+**提示** 为了实现更高级的定制,你也可以注册任意数量的实现了`LettuceClientConfigurationBuilderCustomizer`的bean。如果你使用Jedis,那就实现`JedisClientConfigurationBuilderCustomizer`。
如果你添加一个自己的,或任何自动配置类型的`@Bean`,它将替换默认实例(除了`RedisTemplate`的情况,它是根据`bean`的name 'redisTemplate'而不是类型进行排除的)。如果在classpath路径下存在`commons-pool2`,默认你会获得一个连接池工厂。
diff --git a/IV. Spring Boot features/30.10 InfluxDB.md b/IV. Spring Boot features/30.10 InfluxDB.md
index f4484298..3c82a223 100644
--- a/IV. Spring Boot features/30.10 InfluxDB.md
+++ b/IV. Spring Boot features/30.10 InfluxDB.md
@@ -1,3 +1,3 @@
### 30.10 InfluxDB
-[InfluxDB](https://www.influxdata.com/)是一个开源时序型数据库,着力于在操作监控、应用程序度量、物联网传感器数据和实时分析等领域,快速、高可靠性地存储与查询时序型数据。
\ No newline at end of file
+[InfluxDB](https://www.influxdata.com/)是一个开源时序型数据库,着力于操作监控、应用程序度量、物联网传感器数据和实时分析等领域,快速、高可靠性地存储与查询时序型数据。
diff --git a/IV. Spring Boot features/30.10.1 Connecting to InfluxDB.md b/IV. Spring Boot features/30.10.1 Connecting to InfluxDB.md
index 2bb10fe1..b8605b2e 100644
--- a/IV. Spring Boot features/30.10.1 Connecting to InfluxDB.md
+++ b/IV. Spring Boot features/30.10.1 Connecting to InfluxDB.md
@@ -1,7 +1,10 @@
### 30.10.1 连接InfluxDB
-只要`influxdb-java`客户端在类路径下,而且如下所示,设置了数据库的url,Spring Boot就能自动配置InfluxDB实例。
+只要`influxdb-java`客户端在类路径下,而且设置了数据库的url,Spring Boot就能自动配置InfluxDB实例。如下所示:
```properties
spring.influx.url=http://172.0.0.1:8086
```
-如果连接InfluxDB需要用户名和密码,你可以相应地设置`spring.influx.user`和`spring.influx.password`。
\ No newline at end of file
+
+如果连接InfluxDB需要用户名和密码,你可以相应地设置`spring.influx.user`和`spring.influx.password`。
+
+InfluxDB依赖OkHttp。如果你需要调整http客户端`InfluxDB`在幕后使用,你可以注册一个`OkHttpClient.Builder` bean。
diff --git a/IV. Spring Boot features/30.2. MongoDB.md b/IV. Spring Boot features/30.2. MongoDB.md
index 9b950aa0..3d0ba2b3 100644
--- a/IV. Spring Boot features/30.2. MongoDB.md
+++ b/IV. Spring Boot features/30.2. MongoDB.md
@@ -1,3 +1,3 @@
### 30.2. MongoDB
-[MongoDB](http://www.mongodb.com/)是一个开源的NoSQL文档数据库,它使用类JSON格式的模式(schema)替换了传统的基于表的关系数据。Spring Boot为使用MongoDB提供了很多便利,包括`spring-boot-starter-data-mongodb`和`spring-boot-starter-data-mongodb-reactive`'Starter'。
+[MongoDB](https://www.mongodb.com/)是一个开源的NoSQL文档数据库,它使用类JSON格式的模式(schema)替换了传统的基于表的关系数据。Spring Boot为使用MongoDB提供了很多便利,包括`spring-boot-starter-data-mongodb`和`spring-boot-starter-data-mongodb-reactive`“Starter”。
diff --git a/IV. Spring Boot features/30.2.1. Connecting to a MongoDB Database.md b/IV. Spring Boot features/30.2.1. Connecting to a MongoDB Database.md
new file mode 100644
index 00000000..a7ed4207
--- /dev/null
+++ b/IV. Spring Boot features/30.2.1. Connecting to a MongoDB Database.md
@@ -0,0 +1,40 @@
+### 30.2.1. 连接MongoDB数据库
+
+你可以注入一个自动配置的`org.springframework.data.mongodb.MongoDbFactory`来访问Mongo数据库。默认情况下,该实例将尝试使用URL `mongodb://localhost/test`连接到MongoDB服务器。下面的例子展示了怎么连接到一个MongoDB数据库:
+```java
+import org.springframework.data.mongodb.MongoDbFactory;
+import com.mongodb.DB;
+
+@Component
+public class MyBean {
+
+ private final MongoDbFactory mongo;
+
+ @Autowired
+ public MyBean(MongoDbFactory mongo) {
+ this.mongo = mongo;
+ }
+
+ // ...
+ public void example() {
+ DB db = mongo.getDb();
+ // ...
+ }
+}
+```
+你可以设置`spring.data.mongodb.uri`来改变该URL,并配置其它的设置,比如副本集,如下所示:
+```properties
+spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test
+```
+另外,跟正在使用的Mongo 2.x一样,你可以指定`host`/`port`,比如,在`application.properties`中添加以下配置:
+```java
+spring.data.mongodb.host=mongoserver
+spring.data.mongodb.port=27017
+```
+**注** Mongo 3.0 Java驱动不支持`spring.data.mongodb.host`和`spring.data.mongodb.port`。对于这种情况,`spring.data.mongodb.uri`需要提供全部的配置信息。
+
+**注** 如果没有指定`spring.data.mongodb.port`,默认使用`27017`,上述示例中可以删除这行配置。
+
+**注** 如果不使用Spring Data Mongo,你可以注入`com.mongodb.MongoClient`bean,以代替`MongoDbFactory`。如果想完全控制MongoDB连接的建立过程,你可以声明自己的`MongoDbFactory`或`MongoClient`bean。
+
+**注** 如果你正在使用响应式的驱动,使用SSL需要Netty。如果Netty可用,并且将使用的工厂没有被配置,那么工厂会被自动配置好。
diff --git a/IV. Spring Boot features/30.2.1. Connecting to a MongoDB database.md b/IV. Spring Boot features/30.2.1. Connecting to a MongoDB database.md
deleted file mode 100644
index 7f0cd1b1..00000000
--- a/IV. Spring Boot features/30.2.1. Connecting to a MongoDB database.md
+++ /dev/null
@@ -1,41 +0,0 @@
-### 30.2.1. 连接MongoDB数据库
-
-你可以注入一个自动配置的`org.springframework.data.mongodb.MongoDbFactory`来访问Mongo数据库。默认情况下,该实例将尝试使用URL `mongodb://localhost/test`连接到MongoDB服务器:
-```java
-import org.springframework.data.mongodb.MongoDbFactory;
-import com.mongodb.DB;
-
-@Component
-public class MyBean {
-
- private final MongoDbFactory mongo;
-
- @Autowired
- public MyBean(MongoDbFactory mongo) {
- this.mongo = mongo;
- }
-
- // ...
- public void example() {
- DB db = mongo.getDb();
- // ...
- }
-}
-```
-你可以设置`spring.data.mongodb.uri`来改变该url,并配置其他的设置,比如副本集:
-```properties
-spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test
-```
-另外,跟正在使用的Mongo 2.x一样,你可以指定`host`/`port`,比如,在`application.properties`中添加以下配置:
-```java
-spring.data.mongodb.host=mongoserver
-spring.data.mongodb.port=27017
-```
-**注** Mongo 3.0 Java驱动不支持`spring.data.mongodb.host`和`spring.data.mongodb.port`,对于这种情况,`spring.data.mongodb.uri`需要提供全部的配置信息。
-
-**注** 如果没有指定`spring.data.mongodb.port`,默认使用`27017`,上述示例中可以删除这行配置。
-
-**注** 如果不使用Spring Data Mongo,你可以注入`com.mongodb.Mongo beans`以代替`MongoDbFactory`。
-
-如果想完全控制MongoDB连接的建立过程,你可以声明自己的`MongoDbFactory`或`Mongo` bean。
-如果想全面控制MongoDB连接的建立,你也可以声明自己的MongoDbFactory或Mongo,@Beans。
diff --git a/IV. Spring Boot features/30.2.2. MongoTemplate.md b/IV. Spring Boot features/30.2.2. MongoTemplate.md
index 1ffdbcab..f2957c50 100644
--- a/IV. Spring Boot features/30.2.2. MongoTemplate.md
+++ b/IV. Spring Boot features/30.2.2. MongoTemplate.md
@@ -1,6 +1,6 @@
### 30.2.2. MongoDBTemplate
-Spring Data Mongo提供了一个[MongoTemplate](http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoTemplate.html)类,它的设计和Spring的`JdbcTemplate`很相似。跟`JdbcTemplate`一样,Spring Boot会为你自动配置一个bean,你只需简单的注入即可:
+[Spring Data MongoDB](https://projects.spring.io/spring-data-mongodb/)提供了一个[MongoTemplate](https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoTemplate.html)类。它的设计和Spring的`JdbcTemplate`很相似。跟`JdbcTemplate`一样,Spring Boot会为你自动配置一个bean用来注入模版,如下:
```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -18,4 +18,4 @@ public class MyBean {
// ...
}
```
-具体参考`MongoOperations` Javadoc。
+具体参考[`MongoOperations`Javadoc](https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoOperations.html)。
diff --git a/IV. Spring Boot features/30.2.3. Spring Data MongoDB Repositories.md b/IV. Spring Boot features/30.2.3. Spring Data MongoDB Repositories.md
new file mode 100644
index 00000000..7b109df6
--- /dev/null
+++ b/IV. Spring Boot features/30.2.3. Spring Data MongoDB Repositories.md
@@ -0,0 +1,23 @@
+### 30.2.3. Spring Data MongoDB仓库
+
+Spring Data包含的仓库也支持MongoDB,正如上面讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
+
+实际上,不管是Spring Data JPA还是Spring Data MongoDB都共享相同的基础设施。所以你可以使用上面的JPA示例,并假设那个`City`现在是一个Mongo数据类而不是JPA `@Entity`,它将以同样的方式工作,如下所示:
+```java
+package com.example.myapp.domain;
+
+import org.springframework.data.domain.*;
+import org.springframework.data.repository.*;
+
+public interface CityRepository extends Repository {
+
+ Page findAll(Pageable pageable);
+
+ City findByNameAndCountryAllIgnoringCase(String name, String country);
+
+}
+```
+
+**注** 你可以通过`@EntityScan`注解自定义文档扫描位置。
+
+**注** 想详细了解Spring Data MongoDB,包括它丰富的对象映射技术,可以查看它的[参考文档](https://projects.spring.io/spring-data-mongodb/)。
diff --git a/IV. Spring Boot features/30.2.3. Spring Data MongoDB repositories.md b/IV. Spring Boot features/30.2.3. Spring Data MongoDB repositories.md
deleted file mode 100644
index c3b0ac54..00000000
--- a/IV. Spring Boot features/30.2.3. Spring Data MongoDB repositories.md
+++ /dev/null
@@ -1,20 +0,0 @@
-### 30.2.3. Spring Data MongoDB仓库
-
-Spring Data包含的仓库也支持MongoDB,正如上面讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
-
-实际上,不管是Spring Data JPA还是Spring Data MongoDB都共享相同的基础设施。所以你可以使用上面的JPA示例,并假设那个`City`现在是一个Mongo数据类而不是JPA `@Entity`,它将以同样的方式工作:
-```java
-package com.example.myapp.domain;
-
-import org.springframework.data.domain.*;
-import org.springframework.data.repository.*;
-
-public interface CityRepository extends Repository {
-
- Page findAll(Pageable pageable);
-
- City findByNameAndCountryAllIgnoringCase(String name, String country);
-
-}
-```
-**注** 想详细了解Spring Data MongoDB,包括它丰富的对象映射技术,可以查看它的[参考文档](http://projects.spring.io/spring-data-mongodb/)。
diff --git a/IV. Spring Boot features/30.3 Neo4j.md b/IV. Spring Boot features/30.3 Neo4j.md
index 5bdf5a01..51a57b41 100644
--- a/IV. Spring Boot features/30.3 Neo4j.md
+++ b/IV. Spring Boot features/30.3 Neo4j.md
@@ -1,3 +1,3 @@
### 30.3 Neo4j
-[Neo4j](http://neo4j.com/)是一个开源的NoSQL图数据库,它使用图(graph)相关的概念来描述数据模型,把数据保存为图中的节点以及节点之间的关系。相比传统rdbms(关系管理系统)的方式,Neo4j更适合大数据关系分析。Spring Boot为使用Neo4j提供很多便利,包括`spring-boot-starter-data-neo4j`‘Starter’。
+[Neo4j](http://neo4j.com/)是一个开源的NoSQL图数据库,它使用图(graph)相关的概念来描述数据模型,把数据保存为图中的节点以及节点之间的关系。相比传统rdbms(关系管理系统)的方式,Neo4j更适合大数据关系分析。Spring Boot为使用Neo4j提供很多便利,包括`spring-boot-starter-data-neo4j`“Starter”。
diff --git a/IV. Spring Boot features/30.3.1 Connecting to a Neo4j Database.md b/IV. Spring Boot features/30.3.1 Connecting to a Neo4j Database.md
new file mode 100644
index 00000000..9a0f8b62
--- /dev/null
+++ b/IV. Spring Boot features/30.3.1 Connecting to a Neo4j Database.md
@@ -0,0 +1,27 @@
+### 30.3.1 连接Neo4j数据库
+
+你可以注入一个自动配置的`Neo4jSession`,`Session`,或`Neo4jOperations`实例,就像使用其他Spring Bean那样。该实例默认使用`localhost:7474`连接Neo4j服务器。下面的例子展示了怎么样注入一个Neo4j bean:
+```java
+@Component
+public class MyBean {
+
+ private final Neo4jTemplate neo4jTemplate;
+
+ @Autowired
+ public MyBean(Neo4jTemplate neo4jTemplate) {
+ this.neo4jTemplate = neo4jTemplate;
+ }
+
+ // ...
+
+}
+```
+添加自己的`org.neo4j.ogm.config.Configuration` `@Bean`,你就能完全控制该配置了。同时,添加一个`Neo4jOperations`类型的`@Bean`可以禁用自动配置。
+
+通过`spring.data.neo4j.*`属性可以配置使用的用户和凭证,如下所示:
+
+```properties
+spring.data.neo4j.uri=http://my-server:7474
+spring.data.neo4j.username=neo4j
+spring.data.neo4j.password=secret
+```
diff --git a/IV. Spring Boot features/30.3.1 Connecting to a Neo4j database.md b/IV. Spring Boot features/30.3.1 Connecting to a Neo4j database.md
deleted file mode 100644
index 6a95edc2..00000000
--- a/IV. Spring Boot features/30.3.1 Connecting to a Neo4j database.md
+++ /dev/null
@@ -1,26 +0,0 @@
-### 30.3.1 连接Neo4j数据库
-
-你可以注入一个自动配置的`Neo4jSession`,`Session`,或`Neo4jOperations`实例,就像使用其他Spring Bean那样。该实例默认使用`localhost:7474`连接Neo4j服务器:
-```java
-@Component
-public class MyBean {
-
- private final Neo4jTemplate neo4jTemplate;
-
- @Autowired
- public MyBean(Neo4jTemplate neo4jTemplate) {
- this.neo4jTemplate = neo4jTemplate;
- }
-
- // ...
-
-}
-```
-添加自己的`org.neo4j.ogm.config.Configuration` `@Bean`,你就能完全控制该配置了。同时,添加一个`Neo4jOperations`类型的`@Bean`可以禁用自动配置。
-
-通过`spring.data.neo4j.*`属性可以配置使用的用户和凭证:
-```properties
-spring.data.neo4j.uri=http://my-server:7474
-spring.data.neo4j.username=neo4j
-spring.data.neo4j.password=secret
-```
diff --git a/IV. Spring Boot features/30.3.2 Using the Embedded Mode.md b/IV. Spring Boot features/30.3.2 Using the Embedded Mode.md
new file mode 100644
index 00000000..1a588e3f
--- /dev/null
+++ b/IV. Spring Boot features/30.3.2 Using the Embedded Mode.md
@@ -0,0 +1,9 @@
+### 30.3.2 使用内嵌模式
+
+如果将`org.neo4j:neo4j-ogm-embedded-driver`依赖添加到应用中,Spring Boot会自动配置一个进程内(in-process)的内嵌Neo4j实例,当应用关闭时,该实例不会持久化任何数据。设置`spring.data.neo4j.embedded.enabled=false`可显式关闭该模式。你也可以提供指向数据库文件的路径,来启用内嵌模式的持久化特性,如下所示:
+
+```properties
+spring.data.neo4j.uri=file://var/tmp/graph.db
+```
+
+**注** Neo4j OGM内嵌的驱动不提供Neo4j内核。用户需要手动添加依赖,详情请查看[文档](http://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started)。
diff --git a/IV. Spring Boot features/30.3.2 Using the embedded mode.md b/IV. Spring Boot features/30.3.2 Using the embedded mode.md
deleted file mode 100644
index 9fe5981b..00000000
--- a/IV. Spring Boot features/30.3.2 Using the embedded mode.md
+++ /dev/null
@@ -1,8 +0,0 @@
-### 30.3.2 使用内嵌模式
-
-如果将`org.neo4j:neo4j-ogm-embedded-driver`依赖添加到应用中,Spring Boot会自动配置一个进程内(in-process)的内嵌Neo4j实例,当应用关闭时,该实例不会持久化任何数据。设置`spring.data.neo4j.embedded.enabled=false`可显式关闭该模式,你也可以启用内嵌模式的持久化特性:
-```properties
-spring.data.neo4j.uri=file://var/tmp/graph.db
-```
-
-**注** Neo4j OGM内嵌的驱动不提供Neo4j内核。用户需要手动添加依赖,详情请查看[文档](http://neo4j.com/docs/ogm-manual/current/reference/#reference:getting-started)。
\ No newline at end of file
diff --git a/IV. Spring Boot features/30.3.3 Neo4jSession.md b/IV. Spring Boot features/30.3.3 Neo4jSession.md
index 0780e43e..558f3039 100644
--- a/IV. Spring Boot features/30.3.3 Neo4jSession.md
+++ b/IV. Spring Boot features/30.3.3 Neo4jSession.md
@@ -1,6 +1,7 @@
### 30.3.3 Neo4jSession
-默认地,如果你正在运行一个网络应用,会话会被绑定到请求的整个处理过程的线程上(也就是“在视图中打开会话”模式)。如果你不想要这个行为,在你的`application.properties`中加入下面这句:
+默认地,如果你正在运行一个网络应用,会话会被绑定到请求的整个处理过程的线程上(也就是,它使用“在视图中打开会话”模式)。如果你不想要这个行为,在你的`application.properties`中加入下面这行:
+
```properties
spring.data.neo4j.open-in-view=false
-```
\ No newline at end of file
+```
diff --git a/IV. Spring Boot features/30.3.4 Spring Data Neo4j Repositories.md b/IV. Spring Boot features/30.3.4 Spring Data Neo4j Repositories.md
new file mode 100644
index 00000000..de9a441f
--- /dev/null
+++ b/IV. Spring Boot features/30.3.4 Spring Data Neo4j Repositories.md
@@ -0,0 +1,12 @@
+### 30.3.4 Spring Data Neo4j仓库
+
+Spring Data包含的仓库也支持Neo4j,实际上,Spring Data JPA和Spring Data Neo4j使用相同的常用设施,所以你可以采用先前JPA的示例,假设`City`现在是一个Neo4j OGM `@NodeEntity`而不是JPA `@Entity`,它将以同样的方式工作。
+
+**注** 你可以使用`@EntityScan`注解定义实体扫描路径。
+
+将以下两个注解添加到你的Spring configuration,可以启用repository支持(还有可选的对`@Transactional`的支持):
+
+```java
+@EnableNeo4jRepositories(basePackages = "com.example.myapp.repository")
+@EnableTransactionManagement
+```
diff --git a/IV. Spring Boot features/30.3.4 Spring Data Neo4j repositories.md b/IV. Spring Boot features/30.3.4 Spring Data Neo4j repositories.md
deleted file mode 100644
index d09d9bf6..00000000
--- a/IV. Spring Boot features/30.3.4 Spring Data Neo4j repositories.md
+++ /dev/null
@@ -1,11 +0,0 @@
-### 30.3.4 Spring Data Neo4j仓库
-
-Spring Data包含的仓库也支持Neo4j,实际上,Spring Data JPA和Spring Data Neo4j使用相同的常用设施,所以你可以采用先前JPA的示例,假设`City`现在是一个Neo4j OGM `@NodeEntity`而不是JPA `@Entity`,它将以同样的方式工作。
-
-**注** 你可以使用`@EntityScan`注解定义实体扫描路径。
-
-将以下两个注解添加到你的Spring configuration,可以启用repository支持(还有可选的对`@Transactional`的支持):
-```java
-@EnableNeo4jRepositories(basePackages = "com.example.myapp.repository")
-@EnableTransactionManagement
-```
diff --git a/IV. Spring Boot features/30.3.5 Repository Example.md b/IV. Spring Boot features/30.3.5 Repository Example.md
new file mode 100644
index 00000000..72ae9f3e
--- /dev/null
+++ b/IV. Spring Boot features/30.3.5 Repository Example.md
@@ -0,0 +1,20 @@
+### 30.3.5 仓库示例
+
+下面的例子展示了Neo4j仓库的接口定义:
+
+```java
+package com.example.myapp.domain;
+
+import org.springframework.data.domain.*;
+import org.springframework.data.repository.*;
+
+public interface CityRepository extends GraphRepository {
+
+ Page findAll(Pageable pageable);
+
+ City findByNameAndCountry(String name, String country);
+
+}
+```
+
+**注** 想详细了解Spring Data Neo4j,包括它丰富的对象映射技术,可查看它的[参考文档](https://projects.spring.io/spring-data-neo4j/)。
diff --git a/IV. Spring Boot features/30.3.5 Repository example.md b/IV. Spring Boot features/30.3.5 Repository example.md
deleted file mode 100644
index 52c60862..00000000
--- a/IV. Spring Boot features/30.3.5 Repository example.md
+++ /dev/null
@@ -1,17 +0,0 @@
-### 30.3.5 仓库示例
-
-```java
-package com.example.myapp.domain;
-
-import org.springframework.data.domain.*;
-import org.springframework.data.repository.*;
-
-public interface CityRepository extends GraphRepository {
-
- Page findAll(Pageable pageable);
-
- City findByNameAndCountry(String name, String country);
-
-}
-```
-**注** 想详细了解Spring Data Neo4j,包括它丰富的对象映射技术,可查看它的[参考文档](http://projects.spring.io/spring-data-neo4j/)。
diff --git a/IV. Spring Boot features/30.4 Gemfire.md b/IV. Spring Boot features/30.4 Gemfire.md
index ad893b9c..b262b9f0 100644
--- a/IV. Spring Boot features/30.4 Gemfire.md
+++ b/IV. Spring Boot features/30.4 Gemfire.md
@@ -1,3 +1,3 @@
### 30.4 Gemfire
-[Spring Data Gemfire](https://github.com/spring-projects/spring-data-gemfire)为使用[Pivotal Gemfire](http://www.pivotal.io/big-data/pivotal-gemfire#details)数据管理平台提供了方便的,Spring友好的工具。Spring Boot提供了一个用于聚集依赖的`spring-boot-starter-data-gemfire`'Starter',目前不支持Gemfire的自动配置,但你只需使用[一个注解](https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/config/EnableGemfireRepositories.java)就能使Spring Data仓库支持它。
+[Spring Data Gemfire](https://github.com/spring-projects/spring-data-gemfire)为使用[Pivotal Gemfire](https://pivotal.io/big-data/pivotal-gemfire#details)数据管理平台提供了方便的、对Spring友好的工具。Spring Boot提供了一个用于聚集依赖的`spring-boot-starter-data-gemfire`“Starter”。虽然目前不支持Gemfire的自动配置,但是你可以使用[一个注解:`@EnableGemfireRepositories`](https://github.com/spring-projects/spring-data-gemfire/blob/master/src/main/java/org/springframework/data/gemfire/repository/config/EnableGemfireRepositories.java)启用Spring Data仓库。
diff --git a/IV. Spring Boot features/30.5 Solr.md b/IV. Spring Boot features/30.5 Solr.md
index 0da856b0..93881693 100644
--- a/IV. Spring Boot features/30.5 Solr.md
+++ b/IV. Spring Boot features/30.5 Solr.md
@@ -1,3 +1,3 @@
### 30.5 Solr
-[Apache Solr](http://lucene.apache.org/solr/)是一个搜索引擎。Spring Boot为Solr 5客户端library提供基本的自动配置,[Spring Data Solr](https://github.com/spring-projects/spring-data-solr)提供了在它之上的抽象,还有用于收集依赖的`spring-boot-starter-data-solr`'Starter'。
+[Apache Solr](https://lucene.apache.org/solr/)是一个搜索引擎。Spring Boot为Solr 5客户端library提供基本的自动配置,[Spring Data Solr](https://github.com/spring-projects/spring-data-solr)提供了在它之上的抽象,还有用于收集依赖的`spring-boot-starter-data-solr`”Starter“。
diff --git a/IV. Spring Boot features/30.5.1 Connecting to Solr.md b/IV. Spring Boot features/30.5.1 Connecting to Solr.md
index 25d2bda6..4a8f6684 100644
--- a/IV. Spring Boot features/30.5.1 Connecting to Solr.md
+++ b/IV. Spring Boot features/30.5.1 Connecting to Solr.md
@@ -1,6 +1,6 @@
### 30.5.1 连接Solr
-你可以注入一个自动配置的`SolrClient`实例,就像其他Spring beans那样,该实例默认使用`localhost:8983/solr`连接Solr服务器:
+你可以注入一个自动配置的`SolrClient`实例。就像其他Spring beans那样,该实例默认使用`localhost:8983/solr`连接Solr服务器。下面的例子展示了怎样注入一个Solr bean:
```java
@Component
public class MyBean {
diff --git a/IV. Spring Boot features/30.5.2 Spring Data Solr Repositories.md b/IV. Spring Boot features/30.5.2 Spring Data Solr Repositories.md
new file mode 100644
index 00000000..e2470e99
--- /dev/null
+++ b/IV. Spring Boot features/30.5.2 Spring Data Solr Repositories.md
@@ -0,0 +1,7 @@
+### 30.5.2 Spring Data Solr仓库
+
+Spring Data包含的仓库也支持Apache Solr,正如先前讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
+
+实际上,不管是Spring Data JPA还是Spring Data Solr都共享相同的基础设施。你可以使用先前的JPA示例,并假设那个`City`现在是一个`@SolrDocument`类而不是JPA `@Entity`,它将以同样的方式工作。
+
+**注** 具体参考[Spring Data Solr文档](https://projects.spring.io/spring-data-solr/)。
diff --git a/IV. Spring Boot features/30.5.2 Spring Data Solr repositories.md b/IV. Spring Boot features/30.5.2 Spring Data Solr repositories.md
deleted file mode 100644
index 86efff9e..00000000
--- a/IV. Spring Boot features/30.5.2 Spring Data Solr repositories.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 30.5.2 Spring Data Solr仓库
-
-Spring Data包含的仓库也支持Apache Solr,正如先前讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
-
-实际上,不管是Spring Data JPA还是Spring Data Solr都共享相同的基础设施。所以你可以使用先前的JPA示例,并假设那个`City`现在是一个`@SolrDocument`类而不是JPA `@Entity`,它将以同样的方式工作。
-
-**注** 具体参考[Spring Data Solr文档](http://projects.spring.io/spring-data-solr/)。
diff --git a/IV. Spring Boot features/30.6 Elasticsearch.md b/IV. Spring Boot features/30.6 Elasticsearch.md
index 7f035f96..fefa3ae4 100644
--- a/IV. Spring Boot features/30.6 Elasticsearch.md
+++ b/IV. Spring Boot features/30.6 Elasticsearch.md
@@ -1,3 +1,3 @@
### 30.6 Elasticsearch
-[Elastic Search](http://www.elasticsearch.org/)是一个开源的,分布式,实时搜索和分析引擎。Spring Boot为Elasticsearch提供基本的自动配置,[Spring Data Elasticsearch](https://github.com/spring-projects/spring-data-elasticsearch)提供在它之上的抽象,还有用于收集依赖的`spring-boot-starter-data-elasticsearch`'Starter'。
+[Elastic Search](http://www.elasticsearch.org/)是一个开源的、分布式的、实时搜索和分析引擎。Spring Boot为Elasticsearch提供基本的自动配置。[Spring Data Elasticsearch](https://github.com/spring-projects/spring-data-elasticsearch)提供在它之上的抽象。还有用于收集依赖的`spring-boot-starter-data-elasticsearch`“Starter”。Spring Boot也支持[Jest](https://github.com/searchbox-io/Jest)。
diff --git a/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch by Using Jest.md b/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch by Using Jest.md
new file mode 100644
index 00000000..d984f248
--- /dev/null
+++ b/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch by Using Jest.md
@@ -0,0 +1,25 @@
+### 30.6.1 使用Jest连接Elasticsearch
+
+如果添加`Jest`依赖,你可以注入一个自动配置的`JestClient`,默认目标为`http://localhost:9200/`。你也可以进一步配置该客户端,如下所示:
+
+```properties
+spring.elasticsearch.jest.uris=http://search.example.com:9200
+spring.elasticsearch.jest.read-timeout=10000
+spring.elasticsearch.jest.username=user
+spring.elasticsearch.jest.password=secret
+```
+
+为了实现更高级的定制,你也可以注册任意数量的实现了`HttpClientConfigBuilderCustomizer`的bean。下面的例子调整了额外的HTTP设置。
+
+```java
+static class HttpSettingsCustomizer implements HttpClientConfigBuilderCustomizer {
+
+ @Override
+ public void customize(HttpClientConfig.Builder builder) {
+ builder.maxTotalConnection(100).defaultMaxTotalConnectionPerRoute(5);
+ }
+
+}
+```
+
+定义一个`JestClient` bean以完全控制注册过程。
diff --git a/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch using Jest.md b/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch using Jest.md
deleted file mode 100644
index 0a9fb0c6..00000000
--- a/IV. Spring Boot features/30.6.1 Connecting to Elasticsearch using Jest.md
+++ /dev/null
@@ -1,21 +0,0 @@
-### 30.6.1 使用Jest连接Elasticsearch
-
-如果添加`Jest`依赖,你可以注入一个自动配置的`JestClient`,默认目标为`http://localhost:9200/`,也可以进一步配置该客户端:
-```properties
-spring.elasticsearch.jest.uris=http://search.example.com:9200
-spring.elasticsearch.jest.read-timeout=10000
-spring.elasticsearch.jest.username=user
-spring.elasticsearch.jest.password=secret
-```
-为了实现更高级的定制,你也可以注册任意数量的实现了`HttpClientConfigBuilderCustomizer`的bean。下面的例子调整了额外的HTTP设置。
-```java
-static class HttpSettingsCustomizer implements HttpClientConfigBuilderCustomizer {
-
- @Override
- public void customize(HttpClientConfig.Builder builder) {
- builder.maxTotalConnection(100).defaultMaxTotalConnectionPerRoute(5);
- }
-
-}
-```
-定义一个`JestClient` bean以完全控制注册过程。
diff --git a/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch by Using Spring Data.md b/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch by Using Spring Data.md
new file mode 100644
index 00000000..5036fa55
--- /dev/null
+++ b/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch by Using Spring Data.md
@@ -0,0 +1,24 @@
+### 30.6.2 使用Spring Data连接Elasticsearch
+
+为了连接Elasticsearch,你必须提供一个或者更多的集群节点的地址。可以通过设置`spring.data.elasticsearch.cluster-nodes`(逗号分隔的‘host:port’列表),来指定地址。当配置完成后,`ElasticsearchTemplate`或者`TransportClient`就能够像其它Spring bean一样被注入。如下所示:
+
+```properties
+spring.data.elasticsearch.cluster-nodes=localhost:9300
+```
+
+```java
+@Component
+public class MyBean {
+
+ private final ElasticsearchTemplate template;
+
+ public MyBean(ElasticsearchTemplate template) {
+ this.template = template;
+ }
+
+ // ...
+
+}
+```
+
+如果你添加自己的`ElasticsearchTemplate`或者`TransportClient` `@Bean`,它将覆盖默认实例。
diff --git a/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch using Spring Data.md b/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch using Spring Data.md
deleted file mode 100644
index cb3e3ab5..00000000
--- a/IV. Spring Boot features/30.6.2 Connecting to Elasticsearch using Spring Data.md
+++ /dev/null
@@ -1,21 +0,0 @@
-### 30.6.2 使用Spring Data连接Elasticsearch
-
-为了连接Elasticsearch,你必须提供一个或者更多的集群节点的地址。可以通过设置`spring.data.elasticsearch.cluster-nodes`(逗号分隔的‘host:port’列表),来指定地址。当配置完成后,`ElasticsearchTemplate`或者`TransportClient`就能够像其它Spring bean一样被注入。
-```properties
-spring.data.elasticsearch.cluster-nodes=localhost:9300
-```
-```java
-@Component
-public class MyBean {
-
- private final ElasticsearchTemplate template;
-
- public MyBean(ElasticsearchTemplate template) {
- this.template = template;
- }
-
- // ...
-
-}
-```
-如果你添加自己的`ElasticsearchTemplate`或者`TransportClient``@Bean`,它将覆盖默认实例。
diff --git a/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch Repositories.md b/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch Repositories.md
new file mode 100644
index 00000000..43f2cc38
--- /dev/null
+++ b/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch Repositories.md
@@ -0,0 +1,7 @@
+### 30.6.3 Spring Data Elasticseach仓库
+
+Spring Data包含的仓库也支持Elasticsearch,正如前面讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
+
+实际上,不管是Spring Data JPA还是Spring Data Elasticsearch都共享相同的基础设施。所以你可以使用前面的JPA示例,并假设那个`City`现在是一个Elasticsearch `@Document`类而不是JPA `@Entity`,它将以同样的方式工作。
+
+**注** 具体参考[Spring Data Elasticsearch文档](https://docs.spring.io/spring-data/elasticsearch/docs/)。
diff --git a/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch repositories.md b/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch repositories.md
deleted file mode 100644
index f4a90366..00000000
--- a/IV. Spring Boot features/30.6.3 Spring Data Elasticsearch repositories.md
+++ /dev/null
@@ -1,7 +0,0 @@
-### 30.6.3 Spring Data Elasticseach仓库
-
-Spring Data包含的仓库也支持Elasticsearch,正如前面讨论的JPA仓库,基于方法名自动创建查询是基本的原则。
-
-实际上,不管是Spring Data JPA还是Spring Data Elasticsearch都共享相同的基础设施。所以你可以使用前面的JPA示例,并假设那个`City`现在是一个Elasticsearch `@Document`类而不是JPA `@Entity`,它将以同样的方式工作。
-
-**注** 具体参考[Spring Data Elasticsearch文档](http://docs.spring.io/spring-data/elasticsearch/docs/)。
diff --git a/IV. Spring Boot features/30.7 Cassandra.md b/IV. Spring Boot features/30.7 Cassandra.md
index 55ee494f..53b9023f 100644
--- a/IV. Spring Boot features/30.7 Cassandra.md
+++ b/IV. Spring Boot features/30.7 Cassandra.md
@@ -1,3 +1,3 @@
### 30.7 Cassandra
-[Cassandra](http://cassandra.apache.org/)是一个开源,分布式数据库管理系统,设计用于处理跨很多商品服务器的大数据。Spring Boot为Cassandra提供自动配置,[Spring Data Cassandra](https://github.com/spring-projects/spring-data-cassandra)提供在它之上的抽象,还有收集依赖的`spring-boot-starter-data-cassandra`‘Starter’。
+[Cassandra](https://cassandra.apache.org/)是一个开源的、分布式数据库管理系统,设计用于处理跨很多商品服务器的大数据。Spring Boot为Cassandra提供自动配置。[Spring Data Cassandra](https://github.com/spring-projects/spring-data-cassandra)提供在它之上的抽象。`spring-boot-starter-data-cassandra`“Starter”方便地收集了依赖。
diff --git a/IV. Spring Boot features/30.7.1 Connecting to Cassandra.md b/IV. Spring Boot features/30.7.1 Connecting to Cassandra.md
index 247151a0..4682759d 100644
--- a/IV. Spring Boot features/30.7.1 Connecting to Cassandra.md
+++ b/IV. Spring Boot features/30.7.1 Connecting to Cassandra.md
@@ -1,10 +1,14 @@
### 30.7.1 连接Cassandra
-你可以注入一个自动配置的`CassandraTemplate`或Cassandra `Session`实例,就像注入其他Spring Bean那样。`spring.data.cassandra.*`属性可用来自定义该连接,通常你需要提供`keyspace-name`和`contact-points`属性:
+你可以注入一个自动配置的`CassandraTemplate`或Cassandra `Session`实例,就像注入其他Spring Bean那样。`spring.data.cassandra.*`属性可用来自定义该连接,通常你需要提供`keyspace-name`和`contact-points`属性。如下所示:
+
```properties
spring.data.cassandra.keyspace-name=mykeyspace
spring.data.cassandra.contact-points=cassandrahost1,cassandrahost2
```
+
+下面的代码展示了怎样注入Cassandra bean:
+
```java
@Component
public class MyBean {
@@ -20,4 +24,5 @@ public class MyBean {
}
```
+
如果添加自己的`CassandraTemplate`类型的`@Bean`,它将替换默认实例。
diff --git a/IV. Spring Boot features/30.7.2 Spring Data Cassandra Repositories.md b/IV. Spring Boot features/30.7.2 Spring Data Cassandra Repositories.md
new file mode 100644
index 00000000..b6e24af0
--- /dev/null
+++ b/IV. Spring Boot features/30.7.2 Spring Data Cassandra Repositories.md
@@ -0,0 +1,5 @@
+### 30.7.2 Spring Data Cassandra仓库
+
+Spring Data包含的仓库对Cassandra提供基本支持,目前受到的限制比先前讨论的JPA仓库要多,并且需要使用`@Query`注解相应的查找方法。
+
+**注** 想全面了解Spring Data Cassandra,可查看它的[参考指南](https://docs.spring.io/spring-data/cassandra/docs/)。
diff --git a/IV. Spring Boot features/30.7.2 Spring Data Cassandra repositories.md b/IV. Spring Boot features/30.7.2 Spring Data Cassandra repositories.md
deleted file mode 100644
index a2441b2a..00000000
--- a/IV. Spring Boot features/30.7.2 Spring Data Cassandra repositories.md
+++ /dev/null
@@ -1,5 +0,0 @@
-### 30.7.2 Spring Data Cassandra仓库
-
-Spring Data包含的仓库对Cassandra提供基本支持,目前受到的限制比先前讨论的JPA仓库要多,并且需要使用`@Query`注解相应的查找方法。
-
-**注** 想全面了解Spring Data Cassandra,可查看它的[参考指南](http://docs.spring.io/spring-data/cassandra/docs/)。
diff --git a/IV. Spring Boot features/30.8 Couchbase.md b/IV. Spring Boot features/30.8 Couchbase.md
index b8f3d9d5..dab3d97e 100644
--- a/IV. Spring Boot features/30.8 Couchbase.md
+++ b/IV. Spring Boot features/30.8 Couchbase.md
@@ -1,3 +1,3 @@
### 30.8 Couchbase
-[Couchbase](http://www.couchbase.com/)是一个基于文档,分布式多模型的开源数据库,设计用于交互式应用程序。Spring Boot为Couchbase提供自动配置,[Spring Data Couchbase](https://github.com/spring-projects/spring-data-couchbase)提供在它之上的抽象,还有收集依赖的`spring-boot-starter-data-couchbase`‘Starter’。
+[Couchbase](https://www.couchbase.com/)是一个基于文档的、分布式多模型的开源数据库,设计用于交互式应用程序。Spring Boot为Couchbase提供自动配置,[Spring Data Couchbase](https://github.com/spring-projects/spring-data-couchbase)提供在它之上的抽象,还有收集依赖的`spring-boot-starter-data-couchbase`“Starter”。
diff --git a/IV. Spring Boot features/30.8.1 Connecting to Couchbase.md b/IV. Spring Boot features/30.8.1 Connecting to Couchbase.md
index 955dd326..cdd14d37 100644
--- a/IV. Spring Boot features/30.8.1 Connecting to Couchbase.md
+++ b/IV. Spring Boot features/30.8.1 Connecting to Couchbase.md
@@ -1,17 +1,21 @@
### 30.8.1 连接Couchbase
-通过添加Couchbase SDK和一些配置,你可以很容易获取一个`Bucket`和`Cluster`,`spring.couchbase.*`属性可用于自定义该连接。通常,你需要提供启动hosts,bucket name和password:
+通过添加Couchbase SDK和一些配置,你可以获取一个`Bucket`和`Cluster`,`spring.couchbase.*`属性可用于自定义该连接。通常,你需要提供启动hosts、bucket name和password。如下所示:
+
```properties
spring.couchbase.bootstrap-hosts=my-host-1,192.168.1.123
spring.couchbase.bucket.name=my-bucket
spring.couchbase.bucket.password=secret
```
+
**注** 你至少需要提供启动host(s),在这种情况下,bucket name默认为`default`,password默认为空字符串。另外,你可以定义自己的`org.springframework.data.couchbase.config.CouchbaseConfigurer` `@Bean`来把控所有配置。
你也可以自定义一些`CouchbaseEnvironment`设置,例如,以下配置改变打开新`Bucket`的超时时间(timeout),还启用了SSL支持:
+
```properties
spring.couchbase.env.timeouts.connect=3000
spring.couchbase.env.ssl.key-store=/location/of/keystore.jks
spring.couchbase.env.ssl.key-store-password=secret
```
+
具体查看`spring.couchbase.env.*`属性。
diff --git a/IV. Spring Boot features/30.8.2 Spring Data Couchbase Repositories.md b/IV. Spring Boot features/30.8.2 Spring Data Couchbase Repositories.md
new file mode 100644
index 00000000..e65a216e
--- /dev/null
+++ b/IV. Spring Boot features/30.8.2 Spring Data Couchbase Repositories.md
@@ -0,0 +1,47 @@
+### 30.8.2 Spring Data Couchbase仓库
+
+Spring Data包含的仓库也支持Couchbase,具体可查看Spring Data Couchbase的[参考文档](https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/)。
+
+你可以注入一个自动配置的`CouchbaseTemplate`实例,就像注入其他Spring Bean那样,只要默认的`CouchbaseConfigurer`可以使用。
+
+下面的例子展示了怎么样注入一个Couchbase bean:
+
+```java
+@Component
+public class MyBean {
+
+ private final CouchbaseTemplate template;
+
+ @Autowired
+ public MyBean(CouchbaseTemplate template) {
+ this.template = template;
+ }
+
+ // ...
+
+}
+```
+
+你可以在你自己的配置中定义一些bean,来覆盖自动配置中提供的那些:
+
+* `CouchbaseTemplate` `@Bean` ,称为`couchbaseTemplate`
+* `IndexManager` `@Bean`,称为`couchbaseIndexManager`
+* `CustomConversions` `@Bean`,称为`couchbaseCustomConversions`
+
+为了避免在你的配置中硬编码那些名字,你可以重复使用由Spring Data Couchbase提供的`BeanNames`。例如,你可以像下面这样自定义要使用的转换器:
+
+```java
+@Configuration
+public class SomeConfiguration {
+
+ @Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
+ public CustomConversions myCustomConversions() {
+ return new CustomConversions(...);
+ }
+
+ // ...
+
+}
+```
+
+**提示** 如果想完全关闭Spring Data Couchbase的自动配置,你可以提供自己的`org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration`实现。
diff --git a/IV. Spring Boot features/30.8.2 Spring Data Couchbase repositories.md b/IV. Spring Boot features/30.8.2 Spring Data Couchbase repositories.md
deleted file mode 100644
index 8df2201c..00000000
--- a/IV. Spring Boot features/30.8.2 Spring Data Couchbase repositories.md
+++ /dev/null
@@ -1,41 +0,0 @@
-### 30.8.2 Spring Data Couchbase仓库
-
-Spring Data包含的仓库也支持Couchbase,具体可查看Spring Data Couchbase的[参考文档](http://docs.spring.io/spring-data/couchbase/docs/current/reference/html/)。
-
-你可以注入一个自动配置的`CouchbaseTemplate`实例,就像注入其他Spring Bean那样,只要默认的`CouchbaseConfigurer`可以使用。
-```java
-@Component
-public class MyBean {
-
- private final CouchbaseTemplate template;
-
- @Autowired
- public MyBean(CouchbaseTemplate template) {
- this.template = template;
- }
-
- // ...
-
-}
-```
-你可以在你自己的配置中定义一些bean,来覆盖自动配置中提供的那些:
-
-* `CouchbaseTemplate` `@Bean` ,称为`couchbaseTemplate`
-* `IndexManager` `@Bean`,称为`couchbaseIndexManager`
-* `CustomConversions` `@Bean`,称为`couchbaseCustomConversions`
-
-为了避免在你的配置中硬编码那些名字,你可以重复使用由Spring Data Couchbase提供的`BeanNames`。例如,你可以像下面这样自定义要使用的转换器:
-```java
-@Configuration
-public class SomeConfiguration {
-
- @Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
- public CustomConversions myCustomConversions() {
- return new CustomConversions(...);
- }
-
- // ...
-
-}
-```
-**提示** 如果想完全关闭Spring Data Couchbase的自动配置,你可以提供自己的`org.springframework.data.couchbase.config.AbstractCouchbaseDataConfiguration`实现。
diff --git a/IV. Spring Boot features/30.9 LDAP.md b/IV. Spring Boot features/30.9 LDAP.md
index 090a1ec8..4b0adb2f 100644
--- a/IV. Spring Boot features/30.9 LDAP.md
+++ b/IV. Spring Boot features/30.9 LDAP.md
@@ -1,5 +1,5 @@
### 30.9 LDAP
-[LDAP](https://zh.wikipedia.org/wiki/%E8%BD%BB%E5%9E%8B%E7%9B%AE%E5%BD%95%E8%AE%BF%E9%97%AE%E5%8D%8F%E8%AE%AE) (轻型目录访问协议)是一个开放的,中立的,工业标准的应用协议,通过IP协议提供访问控制和维护分布式信息的目录信息。Spring Boot为任何兼容的LDAP服务器提供自动配置,同时也支持[UnboundID](https://www.ldap.com/unboundid-ldap-sdk-for-java) 的嵌入式内存中LDAP服务器。
+[LDAP](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol) (轻型目录访问协议)是一个开放的、中立的、工业标准的应用协议,通过IP协议提供访问控制和维护分布式信息的目录信息。Spring Boot为任何兼容的LDAP服务器提供自动配置,同时也支持[UnboundID](https://www.ldap.com/unboundid-ldap-sdk-for-java) 的嵌入式内存中LDAP服务器。
-[Spring Data LDAP](https://github.com/spring-projects/spring-data-ldap)提供了LDAP抽象. `spring-boot-starter-data-ldap`”Starter“方便地集合了依赖。
\ No newline at end of file
+[Spring Data LDAP](https://github.com/spring-projects/spring-data-ldap)提供了LDAP抽象。`spring-boot-starter-data-ldap`”Starter“方便地集合了依赖。
diff --git a/IV. Spring Boot features/30.9.1 Connecting to an LDAP Server.md b/IV. Spring Boot features/30.9.1 Connecting to an LDAP Server.md
new file mode 100644
index 00000000..54e6a39f
--- /dev/null
+++ b/IV. Spring Boot features/30.9.1 Connecting to an LDAP Server.md
@@ -0,0 +1,11 @@
+### 30.9.1 连接LDAP服务器
+
+为了连接LDAP服务器,你需要确保声明了`spring-boot-starter-data-ldap`“Starter”或者`spring-ldap-core`依赖,然后在你的`application.properties`中声明你的服务器的URL。如下所示:
+
+```properties
+spring.ldap.urls=ldap://myserver:1235
+spring.ldap.username=admin
+spring.ldap.password=secret
+```
+
+如果你需要自定义连接设置,你可以使用`spring.ldap.base`或者`spring.ldap.base-environment`属性。
diff --git a/IV. Spring Boot features/30.9.1 Connecting to an LDAP server.md b/IV. Spring Boot features/30.9.1 Connecting to an LDAP server.md
deleted file mode 100644
index 290b0a85..00000000
--- a/IV. Spring Boot features/30.9.1 Connecting to an LDAP server.md
+++ /dev/null
@@ -1,9 +0,0 @@
-### 30.9.1 连接LDAP服务器
-
-为了连接LDAP服务器,你需要确保声明了`spring-boot-starter-data-ldap`“Starter”或者`spring-ldap-core`依赖,然后在你的`application.properties`中声明你的服务器的URLs。
-```properties
-spring.ldap.urls=ldap://myserver:1235
-spring.ldap.username=admin
-spring.ldap.password=secret
-```
-如果你需要自定义连接设置,你可以使用`spring.ldap.base`或者`spring.ldap.base-environment`属性。
\ No newline at end of file
diff --git a/IV. Spring Boot features/30.9.2 Spring Data LDAP Repositories.md b/IV. Spring Boot features/30.9.2 Spring Data LDAP Repositories.md
new file mode 100644
index 00000000..9633f606
--- /dev/null
+++ b/IV. Spring Boot features/30.9.2 Spring Data LDAP Repositories.md
@@ -0,0 +1,21 @@
+### 30.9.2 Spring Data LDAP仓库
+
+Spring Data包含了支持LDAP的仓库。Spring Data LDAP的详细情况,请查看他们的[参考文档](https://docs.spring.io/spring-data/ldap/docs/1.0.x/reference/html/)。
+
+你也可以像其它Spring Bean一样,注入一个自动配置的`LdapTemplate`实例。
+
+```java
+@Component
+public class MyBean {
+
+ private final LdapTemplate template;
+
+ @Autowired
+ public MyBean(LdapTemplate template) {
+ this.template = template;
+ }
+
+ // ...
+
+}
+```
diff --git a/IV. Spring Boot features/30.9.2 Spring Data LDAP repositories.md b/IV. Spring Boot features/30.9.2 Spring Data LDAP repositories.md
deleted file mode 100644
index fdab9521..00000000
--- a/IV. Spring Boot features/30.9.2 Spring Data LDAP repositories.md
+++ /dev/null
@@ -1,19 +0,0 @@
-### 30.9.2 Spring Data LDAP仓库
-
-Spring Data包含了支持LDAP的仓库。Spring Data LDAP的详细情况,请查看他们的[参考文档](http://docs.spring.io/spring-data/ldap/docs/1.0.x/reference/html/)。
-你也可以像其它Spring Bean一样,注入一个自动配置的`LdapTemplate`实例。
-```java
-@Component
-public class MyBean {
-
- private final LdapTemplate template;
-
- @Autowired
- public MyBean(LdapTemplate template) {
- this.template = template;
- }
-
- // ...
-
-}
-```
\ No newline at end of file
diff --git a/IV. Spring Boot features/30.9.3 Embedded In-memory LDAP Server.md b/IV. Spring Boot features/30.9.3 Embedded In-memory LDAP Server.md
new file mode 100644
index 00000000..604e5d18
--- /dev/null
+++ b/IV. Spring Boot features/30.9.3 Embedded In-memory LDAP Server.md
@@ -0,0 +1,27 @@
+### 30.9.3 嵌入式内存中LDAP服务器
+
+为了方便测试,Spring Boot支持[UnboundID](https://www.ldap.com/unboundid-ldap-sdk-for-java) 的嵌入式内存中LDAP服务器的自动配置。在`com.unboundid:unboundid-ldapsdk`里添加依赖,声明`base-dn`属性,来配置服务器:
+
+```properties
+spring.ldap.embedded.base-dn=dc=spring,dc=io
+```
+
+**注** 定义多个base-dn的值是可行的。但是,识别名称通常包含逗号。它们必须使用正确的符号定义。
+
+在yaml文件里,你可以使用yaml列表符号:
+```properties
+spring.ldap.embedded.base-dn:
+ - dc=spring,dc=io
+ - dc=pivotal,dc=io
+ ```
+
+在properties文件里,你必须把索引作为属性名的一部分:
+```properties
+spring.ldap.embedded.base-dn[0]=dc=spring,dc=io
+spring.ldap.embedded.base-dn[1]=dc=pivotal,dc=io
+```
+
+默认地,服务器会在一个随机的端口中开始运行。它们会触发常规的LDAP支持(不需要指定`spring.ldap.urls`属性)。
+如果在你的类路径下存在`schema.ldif`文件,它会被用于初始化服务器。如果你想要从不同的资源加载初始化脚本,你可以使用`pring.ldap.embedded.ldif`属性。
+
+默认地,一个标准的模式会被用于验证`LDIF`文件,你可以设置`spring.ldap.embedded.validation.enabled`属性完全地关闭验证。如果你有自定义的属性,你可以使用`spring.ldap.embedded.validation.schema`来定义你的自定义属性类型或对象类。
diff --git a/IV. Spring Boot features/30.9.3 Embedded in-memory LDAP server.md b/IV. Spring Boot features/30.9.3 Embedded in-memory LDAP server.md
deleted file mode 100644
index bc455274..00000000
--- a/IV. Spring Boot features/30.9.3 Embedded in-memory LDAP server.md
+++ /dev/null
@@ -1,9 +0,0 @@
-### 30.9.3 嵌入式内存中LDAP服务器
-
-为了方便测试,Spring Boot支持[UnboundID](https://www.ldap.com/unboundid-ldap-sdk-for-java) 的嵌入式内存中LDAP服务器的自动配置。在`com.unboundid:unboundid-ldapsdk`里添加依赖,声明`base-dn`属性,来配置服务器:
-```properties
-spring.ldap.embedded.base-dn=dc=spring,dc=io
-```
-默认地,服务器会在一个随机的端口中开始运行。它们会触发常规的LDAP支持(不需要指定`spring.ldap.urls`属性)。
-如果在你的类路径下存在`schema.ldif`文件,它会被用于初始化服务器。如果你想要从不同的资源加载初始化脚本,你可以使用`pring.ldap.embedded.ldif`属性。
-默认地,一个标准的模式会被用于验证`LDIF`文件,你可以使用`spring.ldap.embedded.validation.enabled`属性完全地关闭验证。如果你有自定义的属性,你可以使用`spring.ldap.embedded.validation.schema`来定义你的自定义属性类型或对象类。
\ No newline at end of file
diff --git a/IV. Spring Boot features/31. Caching.md b/IV. Spring Boot features/31. Caching.md
index 2dd1294e..394194cc 100644
--- a/IV. Spring Boot features/31. Caching.md
+++ b/IV. Spring Boot features/31. Caching.md
@@ -1,10 +1,10 @@
### 31. 缓存
-Spring框架提供为应用透明添加缓存的支持,核心思想是,将抽象应用到缓存方法,基于缓存中可用信息减少方法的执行。缓存逻辑的应用是透明的,不会干扰调用者。只要通过`@EnableCaching`注解开启缓存支持,Spring Boot就会自动配置缓存基础结构。
+Spring框架提供为应用透明添加缓存的支持。其核心思想是:将抽象应用到缓存方法,基于缓存中可用信息减少方法的执行。缓存逻辑的应用是透明的,不会干扰调用者。只要通过`@EnableCaching`注解开启缓存支持,Spring Boot就会自动配置缓存基础结构。
-**注** 具体参考Spring框架指南的[相应章节](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#cache)。
+**注** 具体参考Spring框架指南的[相应章节](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/integration.html#cache)。
-简而言之,为服务的某个操作添加缓存跟为方法添加相应注解那样简单:
+简而言之,为服务的某个操作添加缓存跟为方法添加相应注解那样简单。如下所示:
```java
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Component;
@@ -23,8 +23,8 @@ public class MathService {
**注** 你也可以透明地使用标准的JSR-107 (JCache)注解(比如`@CacheResult`)。我们强烈建议你不要混淆使用。
-如果你不添加特定的缓存库,Spring Boot将会自动配置一个在内存中使用并发映射的[Simple提供商](../IV. Spring Boot features/31.1.10 Simple.md)。当需要缓存时(比如上面的例子里的`piDecimals`),提供商将会为你实时创建。不推荐你在产品环境中使用Simple提供商。但是它使得入门变得非常容易,确保了你理解特性。当你下定决心使用某个缓存提供商,请阅读这份文档理解如何配置缓存。实际上所有的提供商,都要求你明确地配置你在应用中使用的每一处缓存。有些提供了方法,通过`spring.cache.cache-names`来自定义默认的缓存。
+如果你不添加特定的缓存库,Spring Boot将会自动配置一个在内存中使用并发映射的[Simple提供商](../IV. Spring Boot features/31.1.9 Simple.md)。当需要缓存时(比如上面的例子里的`piDecimals`),提供商将会为你实时创建。不推荐你在产品环境中使用Simple提供商。但是它使得入门变得非常容易,确保了你理解特性。当你下定决心使用某个缓存提供商,请阅读这份文档理解如何配置缓存。实际上所有的提供商,都要求你明确地配置你在应用中使用的每一处缓存。有些提供了方法,通过`spring.cache.cache-names`来自定义默认的缓存。
-**提示** 透明地[更新](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#cache-annotations-put)或[去除](https://docs.spring.io/spring/docs/5.0.0.RELEASE/spring-framework-reference/htmlsingle/#cache-annotations-evict)缓存数据也是可以的。
+**提示** 透明地[更新](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/integration.html#cache-annotations-put)或[去除](https://docs.spring.io/spring/docs/5.0.4.RELEASE/spring-framework-reference/integration.html#cache-annotations-evict)缓存数据也是可以的。
**注** 如果你正在使用的缓存基础结构beans不是基于接口的,确保启用了`@EnableCaching`的`proxyTargetClass`属性。
diff --git a/IV. Spring Boot features/31.1 Supported Cache Providers.md b/IV. Spring Boot features/31.1 Supported Cache Providers.md
new file mode 100644
index 00000000..fa9fcb13
--- /dev/null
+++ b/IV. Spring Boot features/31.1 Supported Cache Providers.md
@@ -0,0 +1,33 @@
+### 31.1 支持的缓存提供商
+
+缓存抽象不提供实际的存储,而是依赖于`org.springframework.cache.Cache`和`org.springframework.cache.CacheManager`接口的实现。
+
+如果你还没有定义一个`CacheManager`类型的bean,或一个名为`cacheResolver`的`CacheResolver`(查看`CachingConfigurer`),Spring Boot将尝试以下提供商(按这个顺序):
+
+ 1. [Generic](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-generic)
+ 2. [JCache (JSR-107)](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-jcache)(EhCache 3, Hazelcast, Infinispan, etc)
+ 3. [EhCache 2.x](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-ehcache2)
+ 4. [Hazelcast](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-hazelcast)
+ 5. [Infinispan](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-infinispan)
+ 6. [Couchbase](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-couchbase)
+ 7. [Redis](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-redis)
+ 8. [Caffeine](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-caffeine)
+ 9. [Simple](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-simple)
+
+ **提示** `spring.cache.type`属性可强制指定使用的缓存提供商,如果需要在一些环境(比如,测试)中[禁用全部缓存](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-caching-provider-none)也可以使用该属性。
+
+ **提示** 使用`spring-boot-starter-cache`“Starter”来快速添加基础的缓存依赖。“Starter”带来了`spring-context-support`:如果你手动添加依赖,为了使用JCache、EhCache2.x或者Guava的支持,你必须添加`spring-context-support`。
+
+ 如果`CacheManager`是Spring Boot自动配置的,你可以在它完全初始化前,通过实现`CacheManagerCustomizer`接口进一步配置,以下设置标志表明空值应当传递给底层映射:
+ ```java
+@Bean
+public CacheManagerCustomizer cacheManagerCustomizer() {
+ return new CacheManagerCustomizer() {
+ @Override
+ public void customize(ConcurrentMapCacheManager cacheManager) {
+ cacheManager.setAllowNullValues(false);
+ }
+ };
+}
+ ```
+ **注** 在以上示例中,希望得到一个自动配置好的`ConcurrentMapCacheManager`。如果没有配置(要么你提供你自己的配置,要么一个不同的缓存提供商被自动配置),则自定义器(customizer)将不会被调用。自定义器你添加多少都可以,并可以使用`@Order`或`Ordered`对它们进行排序。
diff --git a/IV. Spring Boot features/31.1 Supported cache providers.md b/IV. Spring Boot features/31.1 Supported cache providers.md
deleted file mode 100644
index 9c56d981..00000000
--- a/IV. Spring Boot features/31.1 Supported cache providers.md
+++ /dev/null
@@ -1,33 +0,0 @@
-### 31.1 支持的缓存提供商
-
-缓存抽象不提供实际的存储,而是依赖于`org.springframework.cache.Cache`和`org.springframework.cache.CacheManager`接口的实现。
-
-如果你还没有定义一个`CacheManager`类型的bean,或一个名为`cacheResolver`的`CacheResolver`(查看`CachingConfigurer`),Spring Boot将尝试以下提供商(按这个顺序):
-
- * [Generic](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-generic)
- * [JCache (JSR-107)](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-jcache)(EhCache 3, Hazelcast, Infinispan, etc)
- * [EhCache 2.x](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-ehcache2)
- * [Hazelcast](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-hazelcast)
- * [Infinispan](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-infinispan)
- * [Couchbase](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-couchbase)
- * [Redis](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-redis)
- * [Caffeine](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-caffeine)
- * [Simple](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-simple)
-
- **提示** `spring.cache.type`属性可强制指定使用的缓存提供商,如果需要在一些环境(比如,测试)中[禁用全部缓存](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-caching-provider-none)也可以使用该属性。
-
- **提示** 使用`spring-boot-starter-cache`“Starter”来快速添加基础的缓存依赖。“Starter”带来了`spring-context-support`:如果你手动添加依赖,为了使用JCache、EhCache2.x或者Guava的支持,你必须添加`spring-context-support`。
-
- 如果`CacheManager`是Spring Boot自动配置的,你可以在它完全初始化前,通过实现`CacheManagerCustomizer`接口进一步配置,以下设置标志表明空值应当传递给底层映射:
- ```java
-@Bean
-public CacheManagerCustomizer cacheManagerCustomizer() {
- return new CacheManagerCustomizer() {
- @Override
- public void customize(ConcurrentMapCacheManager cacheManager) {
- cacheManager.setAllowNullValues(false);
- }
- };
-}
- ```
- **注** 在以上示例中,希望得到一个自动配置好的`ConcurrentMapCacheManager`。如果没有配置(要么你提供你自己的配置,要么一个不同的缓存提供商被自动配置),则自定义器(customizer)将不会被调用。自定义器你添加多少都可以,并可以使用`@Order`或`Ordered`对它们进行排序。
diff --git a/IV. Spring Boot features/31.1.10 None.md b/IV. Spring Boot features/31.1.10 None.md
index 4cc85f81..b4bf552a 100644
--- a/IV. Spring Boot features/31.1.10 None.md
+++ b/IV. Spring Boot features/31.1.10 None.md
@@ -1,6 +1,7 @@
### 31.1.10 None
-如果配置类中出现`@EnableCaching`,一个合适的缓存配置也同样被期待。如果在某些环境需要禁用全部缓存,强制将缓存类型设为`none`将会使用一个no-op实现(没有任何实现的实现):
+如果配置类中出现`@EnableCaching`,一个合适的缓存配置也同样被期待。如果在某些环境需要禁用全部缓存,强制将缓存类型设为`none`将会使用一个no-op实现(没有任何实现的实现),如下所示:
+
```properties
spring.cache.type=none
```
diff --git "a/IV. Spring Boot features/31.1.2 JCache\357\274\210JSR-107\357\274\211.md" "b/IV. Spring Boot features/31.1.2 JCache\357\274\210JSR-107\357\274\211.md"
index abca3fe1..4b72d9fb 100644
--- "a/IV. Spring Boot features/31.1.2 JCache\357\274\210JSR-107\357\274\211.md"
+++ "b/IV. Spring Boot features/31.1.2 JCache\357\274\210JSR-107\357\274\211.md"
@@ -1,6 +1,6 @@
### 31.1.2 JCache (JSR-107)
-classpath下存在`javax.cache.spi.CachingProvider`(比如,一个遵循JSR-107的缓存library),并且`spring-boot-starter-cache`“Starter”提供了`JCacheCacheManager`,则JCache将启动。这里有很多遵循JSR-107的libraries,Spring Boot为Ehcache 3, Hazelcast和Infinispan提供依赖管理,其他library也可以像这样添加。
+类路径下存在`javax.cache.spi.CachingProvider`(也就是,类路径下存在一个遵循JSR-107的缓存库),并且`spring-boot-starter-cache`“Starter”提供了`JCacheCacheManager`,则[JCache](https://jcp.org/en/jsr/detail?id=107)将启动。这里有很多遵循JSR-107的库,Spring Boot为Ehcache 3、Hazelcast和Infinispan提供依赖管理。也可以添加其他库。
如果出现多个提供商,你需要明确指定使用哪个(提供商)。尽管JSR-107标准没有强制定义配置文件的位置,Spring Boot会尽量配合各实现情况:
```properties
@@ -8,9 +8,10 @@ classpath下存在`javax.cache.spi.CachingProvider`(比如,一个遵循JSR-1
spring.cache.jcache.provider=com.acme.MyCachingProvider
spring.cache.jcache.config=classpath:acme.xml
```
+
**注** 由于一个缓存library可能提供的既有native实现,也有JSR-107支持,Spring Boot将优先使用JSR-107支持,这样如果你切换到不同的JSR-107实现,相同特性依旧可以使用。
-**提示** Spring Boot对Hazelcast有[广泛支持](../IV. Spring Boot features/37. Hazelcast.md)。如果单个的`HazelcastInstance`可用,它就会被`CacheManager`重复使用,除非指定了`spring.cache.jcache.config`属性。
+**提示** Spring Boot对Hazelcast有[广泛支持](../IV. Spring Boot features/38. Hazelcast.md)。如果单个的`HazelcastInstance`可用,它就会被`CacheManager`重复使用,除非指定了`spring.cache.jcache.config`属性。
以下方式可以自定义底层的`javax.cache.cacheManager`:
diff --git a/IV. Spring Boot features/31.1.3 EhCache 2.x.md b/IV. Spring Boot features/31.1.3 EhCache 2.x.md
index d370a78c..9913fd85 100644
--- a/IV. Spring Boot features/31.1.3 EhCache 2.x.md
+++ b/IV. Spring Boot features/31.1.3 EhCache 2.x.md
@@ -1,6 +1,7 @@
### 31.1.3 EhCache 2.x
-如果在classpath下的根目录可以找到一个名为`ehcache.xml`的文件,则缓存将使用EhCache 2.x。如果EhCache 2.x(由`spring-boot-starter-cache`”Starter“提供的`EhCacheCacheManager`)和这样的文件出现,那它们将用于启动缓存管理器,使用以下配置也可以提供替换的配置文件:
+如果类路径下存在一个名为`ehcache.xml`的文件,则缓存将使用[EhCache](http://www.ehcache.org/) 2.x。如果存在EhCache 2.x,由`spring-boot-starter-cache`“Starter”提供的`EhCacheCacheManager`将用于启动缓存管理器。也可以提供一个替代的配置文件,如下所示:
+
```properties
spring.cache.ehcache.config=classpath:config/another-config.xml
```
diff --git a/IV. Spring Boot features/31.1.4 Hazelcast.md b/IV. Spring Boot features/31.1.4 Hazelcast.md
index a57dd022..51f1b084 100644
--- a/IV. Spring Boot features/31.1.4 Hazelcast.md
+++ b/IV. Spring Boot features/31.1.4 Hazelcast.md
@@ -1,3 +1,3 @@
### 31.1.4 Hazelcast
-Spring Boot为Hazelcast提供[通常的支持](https://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#boot-features-hazelcast),如果`HazelcastInstance`被自动配置,那它将自动包装进一个`CacheManager`。
+Spring Boot为Hazelcast提供[通常的支持](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#boot-features-hazelcast)。如果`HazelcastInstance`被自动配置,那它将自动包装进一个`CacheManager`。
diff --git a/IV. Spring Boot features/31.1.5 Infinispan.md b/IV. Spring Boot features/31.1.5 Infinispan.md
index 98038dfa..34b36b0a 100644
--- a/IV. Spring Boot features/31.1.5 Infinispan.md
+++ b/IV. Spring Boot features/31.1.5 Infinispan.md
@@ -1,9 +1,10 @@
### 31.1.5 Infinispan
-Infinispan没有默认的配置文件位置,所以需要显式指定:
+Infinispan没有默认的配置文件位置,所以必须显式指定。否则,会使用默认的启动。
```properties
spring.cache.infinispan.config=infinispan.xml
```
-通过设置`spring.cache.cache-names`属性可以让缓存在启动时就被创建,如果定义了`ConfigurationBuilder` bean,它将用来定义该实例。
-**提示** Spring Boot对Infinispan的嵌入模式的支持受限,而且相当基础。如果你需要更多的选择项,你应当使用官方的Infinispan Spring Boot starter,查看[文档](https://github.com/infinispan/infinispan-spring-boot)获取更多详细情况。
+通过设置`spring.cache.cache-names`属性可以让缓存在启动时就被创建。如果定义了自定义的`ConfigurationBuilder` bean,它将用来自定义缓存。
+
+**提示** Spring Boot对Infinispan的嵌入模式的支持受限,而且相当基础。如果你需要更多的选择项,你应当使用官方的Infinispan Spring Boot starter。查看[文档](https://github.com/infinispan/infinispan-spring-boot)获取更多详细情况。
diff --git a/IV. Spring Boot features/31.1.6 Couchbase.md b/IV. Spring Boot features/31.1.6 Couchbase.md
index 942a7c64..7eee3956 100644
--- a/IV. Spring Boot features/31.1.6 Couchbase.md
+++ b/IV. Spring Boot features/31.1.6 Couchbase.md
@@ -1,10 +1,12 @@
### 31.1.6 Couchbase
-如果Couchbase Java客户端和`couchbase-spring-cache`实现可用,并且已经配置好了,`CouchbaseCacheManager`将会自动配置,使用`spring.cache.cache-names`属性可以在启动时创建其他缓存。对`Bucket`的操作也是自动配置的,你可以使用customizer在另一个`Bucket`上创建其他缓存:假设你需要在“main” `Bucket`上存放两个缓存(`foo`和`bar`),在另一个`Bucket`上存放一个存活时间为2秒的`biz`缓存。首先,你通过配置创建两个缓存:
+如果[Couchbase](https://www.couchbase.com/) Java客户端和`couchbase-spring-cache`实现可用,并且已经配置好了,`CouchbaseCacheManager`将会自动配置,使用`spring.cache.cache-names`属性可以在启动时创建其他缓存。对`Bucket`的操作也是自动配置的,你可以使用customizer在另一个`Bucket`上创建其他缓存:假设你需要在“main” `Bucket`上存放两个缓存(`cache1`和`cache2`),在另一个`Bucket`上存放一个存活时间为2秒的`cache3`缓存。首先,你通过配置创建两个缓存:
+
```properties
-spring.cache.cache-names=foo,bar
+spring.cache.cache-names=cache1,cache2
```
-然后定义其他`@Configuration`来配置另一个`Bucket`和`biz`缓存:
+
+然后定义其他`@Configuration`来配置另一个`Bucket`和`cache3`缓存:
```java
@Configuration
public class CouchbaseCacheConfiguration {
@@ -23,7 +25,7 @@ public class CouchbaseCacheConfiguration {
@Bean
public CacheManagerCustomizer cacheManagerCustomizer() {
return c -> {
- c.prepareCache("biz", CacheBuilder.newInstance(anotherBucket())
+ c.prepareCache("cache3", CacheBuilder.newInstance(anotherBucket())
.withExpiration(2));
};
}
diff --git a/IV. Spring Boot features/31.1.7 Redis.md b/IV. Spring Boot features/31.1.7 Redis.md
index ad90dc6d..47d9d18e 100644
--- a/IV. Spring Boot features/31.1.7 Redis.md
+++ b/IV. Spring Boot features/31.1.7 Redis.md
@@ -1,5 +1,13 @@
### 31.1.7 Redis
-如果Redis可用,并配置好了,`RedisCacheManager`将被自动配置,使用`spring.cache.cache-names`可以在启动时创建其他缓存。
+如果[Redis](http://redis.io/)可用,并配置好了,`RedisCacheManager`将被自动配置。设置`spring.cache.cache-names`属性可以在启动时创建额外的缓存。使用`spring.cache.redis.*`属性可以配置缓存的默认值。比如,下面的配置会创建缓存`cache1`和`cache2`。它们的存活时间为10分钟。
+
+```properties
+spring.cache.cache-names=cache1,cache2
+spring.cache.redis.time-to-live=600000
+```
**注** 默认会添加key前缀以防止两个单独的缓存使用相同的key,否则Redis将存在重复的key,有可能返回不可用的值。如果创建自己的`RedisCacheManager`,强烈建议你保留该配置处于启用状态。
+
+
+**注** 你可以添加自己的`RedisCacheConfiguration` `@Bean`,完全掌控配置。如果你正在寻找自定义序列化策略,这会很有用。
diff --git a/IV. Spring Boot features/31.1.8 Caffeine.md b/IV. Spring Boot features/31.1.8 Caffeine.md
index d4df468d..595e7ee0 100644
--- a/IV. Spring Boot features/31.1.8 Caffeine.md
+++ b/IV. Spring Boot features/31.1.8 Caffeine.md
@@ -1,14 +1,15 @@
### 31.1.8 Caffeine
-Caffeine是Java8对Guava缓存的重写版本,取代了Guava。如果出现Caffeine,`CaffeineCacheManager`(由`spring-boot-starter-cache` Starter提供)将会自动配置。使用`spring.cache.cache-names`属性可以在启动时创建缓存,并可以通过以下配置进行自定义(按顺序):
+[Caffeine](https://github.com/ben-manes/caffeine)是Java 8对Guava缓存的重写版本,取代了Guava。如果出现Caffeine,`CaffeineCacheManager`(由`spring-boot-starter-cache` Starter提供)将会自动配置。使用`spring.cache.cache-names`属性可以在启动时创建缓存,并可以通过以下配置中的一个进行自定义(按指示的顺序):
1. `spring.cache.caffeine.spec`定义的特殊缓存
2. `com.github.benmanes.caffeine.cache.CaffeineSpec` bean定义
3. `com.github.benmanes.caffeine.cache.Caffeine` bean定义
-例如,以下配置创建一个`foo`和`bar`缓存,最大数量为500,存活时间为10分钟:
+例如,以下配置创建一个`cache1 `和`cache2`缓存,最大数量为500,存活时间为10分钟:
```properties
-spring.cache.cache-names=foo,bar
+spring.cache.cache-names=cache1,cache2
spring.cache.caffeine.spec=maximumSize=500,expireAfterAccess=600s
```
-除此之外,如果定义了`com.github.benmanes.caffeine.cache.CacheLoader`,它会自动关联到`CaffeineCacheManager`。由于该`CacheLoader`将关联被该缓存管理器管理的所有缓存,所以它必须定义为`CacheLoader