commit
f81921c005
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,7 +351,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void settingEnvironmentPrefixViaPropertiesThrowsException() {
|
||||
assertThatIllegalStateException()
|
||||
|
|
@ -1735,4 +1758,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue