Skip to content

Commit 66d4319

Browse files
committed
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
1 parent d1867c1 commit 66d4319

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void prepareContext(ConfigurableApplicationContext context, Configurable
394394
}
395395

396396
private void refreshContext(ConfigurableApplicationContext context) {
397-
refresh(context);
397+
refresh((ApplicationContext) context);
398398
if (this.registerShutdownHook) {
399399
try {
400400
context.registerShutdownHook();
@@ -741,10 +741,21 @@ protected BeanDefinitionLoader createBeanDefinitionLoader(BeanDefinitionRegistry
741741
/**
742742
* Refresh the underlying {@link ApplicationContext}.
743743
* @param applicationContext the application context to refresh
744+
* @deprecated since 2.3.0 in favor of
745+
* {@link #refresh(ConfigurableApplicationContext)}
744746
*/
747+
@Deprecated
745748
protected void refresh(ApplicationContext applicationContext) {
746-
Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext);
747-
((AbstractApplicationContext) applicationContext).refresh();
749+
Assert.isInstanceOf(ConfigurableApplicationContext.class, applicationContext);
750+
refresh((ConfigurableApplicationContext) applicationContext);
751+
}
752+
753+
/**
754+
* Refresh the underlying {@link ApplicationContext}.
755+
* @param applicationContext the application context to refresh
756+
*/
757+
protected void refresh(ConfigurableApplicationContext applicationContext) {
758+
applicationContext.refresh();
748759
}
749760

750761
/**

0 commit comments

Comments
 (0)