From 38b0770c79a66daedaf4690da056f46c620053c8 Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Sun, 8 Feb 2015 21:30:57 +0800 Subject: [PATCH] Update 22.3. Fluent builder API.md --- IV. Spring Boot features/22.3. Fluent builder API.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/IV. Spring Boot features/22.3. Fluent builder API.md b/IV. Spring Boot features/22.3. Fluent builder API.md index e69de29..55f6a5f 100644 --- a/IV. Spring Boot features/22.3. Fluent builder API.md +++ b/IV. Spring Boot features/22.3. Fluent builder API.md @@ -0,0 +1,11 @@ +### 22.3. 流畅的构建API + +如果你需要创建一个分层的ApplicationContext(多个具有父子关系的上下文),或你只是喜欢使用流畅的构建API,你可以使用SpringApplicationBuilder。SpringApplicationBuilder允许你以链式方式调用多个方法,包括可以创建层次结构的parent和child方法。 +```java +new SpringApplicationBuilder() + .showBanner(false) + .sources(Parent.class) + .child(Application.class) + .run(args); +``` +**注**:创建ApplicationContext层次时有些限制,比如,Web组件(components)必须包含在子上下文(child context)中,且相同的Environment即用于父上下文也用于子上下文中。具体参考[SpringApplicationBuilder javadoc](http://docs.spring.io/spring-boot/docs/1.2.2.BUILD-SNAPSHOT/api/org/springframework/boot/builder/SpringApplicationBuilder.html)