Skip to content

Commit 8c220d6

Browse files
committed
Merge pull request #25400 from cprayer
* gh-25400: Polish "Add Bootstrapper initialize method to fix typo" Add Bootstrapper initialize method to fix typo Closes gh-25400
2 parents ddf75f0 + f9ef05f commit 8c220d6

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public interface Bootstrapper {
3131
* Initialize the given {@link BootstrapRegistry} with any required registrations.
3232
* @param registry the registry to initialize
3333
*/
34+
default void initialize(BootstrapRegistry registry) {
35+
intitialize(registry);
36+
}
37+
38+
/**
39+
* Initialize the given {@link BootstrapRegistry} with any required registrations.
40+
* @param registry the registry to initialize
41+
* @deprecated since 2.4.4 in favor of
42+
* {@link Bootstrapper#initialize(BootstrapRegistry)}
43+
*/
44+
@Deprecated
3445
void intitialize(BootstrapRegistry registry);
3546

3647
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public ConfigurableApplicationContext run(String... args) {
349349

350350
private DefaultBootstrapContext createBootstrapContext() {
351351
DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
352-
this.bootstrappers.forEach((initializer) -> initializer.intitialize(bootstrapContext));
352+
this.bootstrappers.forEach((initializer) -> initializer.initialize(bootstrapContext));
353353
return bootstrapContext;
354354
}
355355

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,29 @@ void addBootstrapperCanRegisterBeans() {
12471247
assertThat(applicationContext.getBean("test")).isEqualTo("boot");
12481248
}
12491249

1250+
@Test
1251+
void whenABootstrapperImplementsOnlyTheOldMethodThenItIsCalled() {
1252+
SpringApplication application = new SpringApplication(ExampleConfig.class);
1253+
application.setWebApplicationType(WebApplicationType.NONE);
1254+
OnlyOldMethodTestBootstrapper bootstrapper = new OnlyOldMethodTestBootstrapper();
1255+
application.addBootstrapper(bootstrapper);
1256+
try (ConfigurableApplicationContext applicationContext = application.run()) {
1257+
assertThat(bootstrapper.intitialized).isTrue();
1258+
}
1259+
}
1260+
1261+
@Test
1262+
void whenABootstrapperImplementsTheOldMethodAndTheNewMethodThenOnlyTheNewMethodIsCalled() {
1263+
SpringApplication application = new SpringApplication(ExampleConfig.class);
1264+
application.setWebApplicationType(WebApplicationType.NONE);
1265+
BothMethodsTestBootstrapper bootstrapper = new BothMethodsTestBootstrapper();
1266+
application.addBootstrapper(bootstrapper);
1267+
try (ConfigurableApplicationContext applicationContext = application.run()) {
1268+
assertThat(bootstrapper.intitialized).isFalse();
1269+
assertThat(bootstrapper.initialized).isTrue();
1270+
}
1271+
}
1272+
12501273
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(
12511274
S state) {
12521275
return (argument) -> (argument instanceof AvailabilityChangeEvent<?>)
@@ -1720,4 +1743,35 @@ <E extends ApplicationEvent> E getEvent(Class<E> type) {
17201743

17211744
}
17221745

1746+
static class OnlyOldMethodTestBootstrapper implements Bootstrapper {
1747+
1748+
private boolean intitialized;
1749+
1750+
@Override
1751+
@SuppressWarnings("deprecation")
1752+
public void intitialize(BootstrapRegistry registry) {
1753+
this.intitialized = true;
1754+
}
1755+
1756+
}
1757+
1758+
static class BothMethodsTestBootstrapper implements Bootstrapper {
1759+
1760+
private boolean intitialized;
1761+
1762+
private boolean initialized;
1763+
1764+
@Override
1765+
@SuppressWarnings("deprecation")
1766+
public void intitialize(BootstrapRegistry registry) {
1767+
this.intitialized = true;
1768+
}
1769+
1770+
@Override
1771+
public void initialize(BootstrapRegistry registry) {
1772+
this.initialized = true;
1773+
}
1774+
1775+
}
1776+
17231777
}

0 commit comments

Comments
 (0)