From e5f896258b827614b9723aba8e87f19f29214af8 Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Wed, 25 Mar 2015 22:39:26 +0800 Subject: [PATCH] Update 64.13. Enable Multiple Listeners with Undertow.md --- ...13. Enable Multiple Listeners with Undertow.md | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/IX. ‘How-to’ guides/64.13. Enable Multiple Listeners with Undertow.md b/IX. ‘How-to’ guides/64.13. Enable Multiple Listeners with Undertow.md index bcc2cd1..4cba1da 100644 --- a/IX. ‘How-to’ guides/64.13. Enable Multiple Listeners with Undertow.md +++ b/IX. ‘How-to’ guides/64.13. Enable Multiple Listeners with Undertow.md @@ -1,22 +1,18 @@ +### 64.13. 启用Undertow的多监听器(Multiple Listeners) -### 64.13. 发现运行时的HTTP端口 - -你可以通过日志输出或它的EmbeddedServletContainer的EmbeddedWebApplicationContext获取服务器正在运行的端口。获取和确认服务器已经初始化的最好方式是添加一个`ApplicationListener`类型的`@Bean`,然后当事件发布时将容器pull出来。 - -使用`@WebIntegrationTests`的一个有用实践是设置`server.port=0`,然后使用`@Value`注入实际的('local')端口。例如: +往`UndertowEmbeddedServletContainerFactory`添加一个`UndertowBuilderCustomizer`,然后添加一个监听者到`Builder`: ```java -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class) -@WebIntegrationTest("server.port:0") -public class CityRepositoryIntegrationTests { +@Bean +public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() { + UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory(); + factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { - @Autowired - EmbeddedWebApplicationContext server; - - @Value("${local.server.port}") - int port; - - // ... + @Override + public void customize(Builder builder) { + builder.addHttpListener(8080, "0.0.0.0"); + } + }); + return factory; } ```