From 2f513400475306ff34da81ab24f97ebfe6b8d433 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sun, 20 Aug 2017 18:28:35 +0200 Subject: [PATCH] Restore WebServerInitializedEvent listener registration This commit fixes ServerPortInfoApplicationContextInitializer so that is registers a listener against `WebServerInitializedEvent`. A former polish to use a lambda actually introduced a regression as the listener was registered as `ApplicationListener`. Closes gh-10047 --- .../ServerPortInfoApplicationContextInitializer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java index 33445c8d813..146bbbd1a4a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.server.WebServer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -48,15 +49,15 @@ import org.springframework.core.env.PropertySource; * @since 2.0.0 */ public class ServerPortInfoApplicationContextInitializer - implements ApplicationContextInitializer { + implements ApplicationContextInitializer, ApplicationListener { @Override public void initialize(ConfigurableApplicationContext applicationContext) { - applicationContext.addApplicationListener( - (WebServerInitializedEvent event) -> onApplicationEvent(event)); + applicationContext.addApplicationListener(this); } - protected void onApplicationEvent(WebServerInitializedEvent event) { + @Override + public void onApplicationEvent(WebServerInitializedEvent event) { String propertyName = "local." + event.getServerId() + ".port"; setPortProperty(event.getApplicationContext(), propertyName, event.getWebServer().getPort());