From bee6f41393a5d6aa3c67a834bffdfb20dc8159cb Mon Sep 17 00:00:00 2001 From: cprayer Date: Thu, 25 Feb 2021 10:00:12 +0900 Subject: [PATCH 1/2] Add Bootstrapper initialize method to fix typo See gh-25400 --- .../java/org/springframework/boot/Bootstrapper.java | 11 +++++++++++ .../org/springframework/boot/SpringApplication.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/Bootstrapper.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/Bootstrapper.java index 4e67042bece..b9f13813fe7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/Bootstrapper.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/Bootstrapper.java @@ -31,6 +31,17 @@ public interface Bootstrapper { * Initialize the given {@link BootstrapRegistry} with any required registrations. * @param registry the registry to initialize */ + default void initialize(BootstrapRegistry registry) { + intitialize(registry); + } + + /** + * Initialize the given {@link BootstrapRegistry} with any required registrations. + * @param registry the registry to initialize + * @deprecated since 2.4.4 in favor of + * {@link Bootstrapper#initialize(BootstrapRegistry)} + */ + @Deprecated void intitialize(BootstrapRegistry registry); } 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 f69cf897b58..1e7bcb3c831 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 @@ -349,7 +349,7 @@ public class SpringApplication { private DefaultBootstrapContext createBootstrapContext() { DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext(); - this.bootstrappers.forEach((initializer) -> initializer.intitialize(bootstrapContext)); + this.bootstrappers.forEach((initializer) -> initializer.initialize(bootstrapContext)); return bootstrapContext; } From f9ef05f71e2d537035dc2a4d56393a34133c80e4 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 5 Mar 2021 14:48:13 +0000 Subject: [PATCH 2/2] Polish "Add Bootstrapper initialize method to fix typo" See gh-25400 --- .../boot/SpringApplicationTests.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 5137ec68505..3b3db3a82f6 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -1247,6 +1247,29 @@ class SpringApplicationTests { assertThat(applicationContext.getBean("test")).isEqualTo("boot"); } + @Test + void whenABootstrapperImplementsOnlyTheOldMethodThenItIsCalled() { + SpringApplication application = new SpringApplication(ExampleConfig.class); + application.setWebApplicationType(WebApplicationType.NONE); + OnlyOldMethodTestBootstrapper bootstrapper = new OnlyOldMethodTestBootstrapper(); + application.addBootstrapper(bootstrapper); + try (ConfigurableApplicationContext applicationContext = application.run()) { + assertThat(bootstrapper.intitialized).isTrue(); + } + } + + @Test + void whenABootstrapperImplementsTheOldMethodAndTheNewMethodThenOnlyTheNewMethodIsCalled() { + SpringApplication application = new SpringApplication(ExampleConfig.class); + application.setWebApplicationType(WebApplicationType.NONE); + BothMethodsTestBootstrapper bootstrapper = new BothMethodsTestBootstrapper(); + application.addBootstrapper(bootstrapper); + try (ConfigurableApplicationContext applicationContext = application.run()) { + assertThat(bootstrapper.intitialized).isFalse(); + assertThat(bootstrapper.initialized).isTrue(); + } + } + private ArgumentMatcher isAvailabilityChangeEventWithState( S state) { return (argument) -> (argument instanceof AvailabilityChangeEvent) @@ -1720,4 +1743,35 @@ class SpringApplicationTests { } + static class OnlyOldMethodTestBootstrapper implements Bootstrapper { + + private boolean intitialized; + + @Override + @SuppressWarnings("deprecation") + public void intitialize(BootstrapRegistry registry) { + this.intitialized = true; + } + + } + + static class BothMethodsTestBootstrapper implements Bootstrapper { + + private boolean intitialized; + + private boolean initialized; + + @Override + @SuppressWarnings("deprecation") + public void intitialize(BootstrapRegistry registry) { + this.intitialized = true; + } + + @Override + public void initialize(BootstrapRegistry registry) { + this.initialized = true; + } + + } + }