From 66d4319abd9f5bde94354974b24ab5c93b03aecf Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Sat, 25 Jan 2020 20:24:30 +0000 Subject: [PATCH] Deprecate refresh(ApplicationContext) and add refresh(ConfigurableAC) refresh can only ever be called with a ConfigurableApplicationContext and we want to evolve the refresh API to reflect that. This commit takes the first step by overloading refresh(ApplicationContext) with a new refresh(ConfigurationApplicationContext) method and deprecating refresh(ApplicationContext). Where the call to refresh is made, the argument is cast to ApplicationContext to ensure that refresh(ApplicationContext) is called. This ensures that any existing override of the method is still effective. Closes gh-18519 --- .../springframework/boot/SpringApplication.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 5ca1aa695e..b440012fc5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -394,7 +394,7 @@ public class SpringApplication { } private void refreshContext(ConfigurableApplicationContext context) { - refresh(context); + refresh((ApplicationContext) context); if (this.registerShutdownHook) { try { context.registerShutdownHook(); @@ -741,10 +741,21 @@ public class SpringApplication { /** * Refresh the underlying {@link ApplicationContext}. * @param applicationContext the application context to refresh + * @deprecated since 2.3.0 in favor of + * {@link #refresh(ConfigurableApplicationContext)} */ + @Deprecated protected void refresh(ApplicationContext applicationContext) { - Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext); - ((AbstractApplicationContext) applicationContext).refresh(); + Assert.isInstanceOf(ConfigurableApplicationContext.class, applicationContext); + refresh((ConfigurableApplicationContext) applicationContext); + } + + /** + * Refresh the underlying {@link ApplicationContext}. + * @param applicationContext the application context to refresh + */ + protected void refresh(ConfigurableApplicationContext applicationContext) { + applicationContext.refresh(); } /**