SpringBoot官方文档翻译(三十三):流式编程接口

23.4 Fluent Builder API(流式编程接口)

1
2
3
If you need to build an ApplicationContext hierarchy (multiple contexts     
with a parent/child relationship) or if you prefer using a “fluent”
builder API, you can use the SpringApplicationBuilder.

如果您需要构建ApplicationContext层次结构(具有父/子关系的多个上下文),或者如果您更愿意使用“流式”构建器API,则可以使用SpringApplicationBuilder。

1
2
3
The SpringApplicationBuilder lets you chain together multiple method     
calls and includes parent and child methods that let you create a
hierarchy, as shown in the following example:

SpringApplicationBuilder可以让您将多个方法之间的调用使用父子关系的方式链接起来,如下:

1
2
3
4
5
new SpringApplicationBuilder()
.sources(Parent.class)
.child(Application.class)
.bannerMode(Banner.Mode.OFF)
.run(args);

1
2
3
4
5
There are some restrictions when creating an ApplicationContext     
hierarchy. For example, Web components must be contained within
the child context, and the same Environment is used for both parent
and child contexts. See the SpringApplicationBuilder Javadoc for
full details.

像这种链式编程有一些限制。例如,Web组件必须包含在子上下文中,一些环境变量即会被用在父上下文中也会用在子上下文中。具体可以参考SpringApplicationBuilder的Javadoc。

分享到