Rename ApplicationStartedEvent
Rename `ApplicationStartedEvent` to `ApplicationStartingEvent` to avoid confusion. Fixes gh-7381
This commit is contained in:
parent
0e3a3df6f4
commit
e7db7adfb8
|
@ -19,7 +19,7 @@ package org.springframework.boot.devtools.restart;
|
|||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
|
@ -41,8 +41,8 @@ public class RestartApplicationListener
|
|||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ApplicationStartedEvent) {
|
||||
onApplicationStartedEvent((ApplicationStartedEvent) event);
|
||||
if (event instanceof ApplicationStartingEvent) {
|
||||
onApplicationStartingEvent((ApplicationStartingEvent) event);
|
||||
}
|
||||
if (event instanceof ApplicationPreparedEvent) {
|
||||
Restarter.getInstance()
|
||||
|
@ -57,7 +57,7 @@ public class RestartApplicationListener
|
|||
}
|
||||
}
|
||||
|
||||
private void onApplicationStartedEvent(ApplicationStartedEvent event) {
|
||||
private void onApplicationStartingEvent(ApplicationStartingEvent event) {
|
||||
// It's too early to use the Spring environment but we should still allow
|
||||
// users to disable restart using a System property.
|
||||
String enabled = System.getProperty(ENABLED_PROPERTY);
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
@ -92,7 +92,7 @@ public class RestartApplicationListenerTests {
|
|||
SpringApplication application = new SpringApplication();
|
||||
ConfigurableApplicationContext context = mock(
|
||||
ConfigurableApplicationContext.class);
|
||||
listener.onApplicationEvent(new ApplicationStartedEvent(application, ARGS));
|
||||
listener.onApplicationEvent(new ApplicationStartingEvent(application, ARGS));
|
||||
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
|
||||
assertThat(Restarter.getInstance().isFinished()).isFalse();
|
||||
listener.onApplicationEvent(
|
||||
|
|
|
@ -299,7 +299,7 @@ public class SpringApplication {
|
|||
FailureAnalyzers analyzers = null;
|
||||
configureHeadlessProperty();
|
||||
SpringApplicationRunListeners listeners = getRunListeners(args);
|
||||
listeners.started();
|
||||
listeners.starting();
|
||||
try {
|
||||
ApplicationArguments applicationArguments = new DefaultApplicationArguments(
|
||||
args);
|
||||
|
|
|
@ -37,7 +37,7 @@ public interface SpringApplicationRunListener {
|
|||
* Called immediately when the run method has first started. Can be used for very
|
||||
* early initialization.
|
||||
*/
|
||||
void started();
|
||||
void starting();
|
||||
|
||||
/**
|
||||
* Called once the environment has been prepared, but before the
|
||||
|
|
|
@ -43,9 +43,9 @@ class SpringApplicationRunListeners {
|
|||
this.listeners = new ArrayList<SpringApplicationRunListener>(listeners);
|
||||
}
|
||||
|
||||
public void started() {
|
||||
public void starting() {
|
||||
for (SpringApplicationRunListener listener : this.listeners) {
|
||||
listener.started();
|
||||
listener.starting();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,11 @@ import org.springframework.core.env.Environment;
|
|||
* state too much at this early stage since it might be modified later in the lifecycle.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @deprecated since 1.5.0 in favor of {@link ApplicationStartingEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class ApplicationStartedEvent extends SpringApplicationEvent {
|
||||
public class ApplicationStartedEvent extends ApplicationStartingEvent {
|
||||
|
||||
/**
|
||||
* Create a new {@link ApplicationStartedEvent} instance.
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.event;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Event published as early as conceivably possible as soon as a {@link SpringApplication}
|
||||
* has been started - before the {@link Environment} or {@link ApplicationContext} is
|
||||
* available, but after the {@link ApplicationListener}s have been registered. The source
|
||||
* of the event is the {@link SpringApplication} itself, but beware of using its internal
|
||||
* state too much at this early stage since it might be modified later in the lifecycle.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Madhura Bhave
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ApplicationStartingEvent extends SpringApplicationEvent {
|
||||
|
||||
/**
|
||||
* Create a new {@link ApplicationStartingEvent} instance.
|
||||
* @param application the current application
|
||||
* @param args the arguments the application is running with
|
||||
*/
|
||||
public ApplicationStartingEvent(SpringApplication application, String[] args) {
|
||||
super(application, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -58,7 +58,8 @@ public class EventPublishingRunListener implements SpringApplicationRunListener,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void started() {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void starting() {
|
||||
this.initialMulticaster
|
||||
.multicastEvent(new ApplicationStartedEvent(this.application, this.args));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import liquibase.servicelocator.ServiceLocator;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
@ -33,13 +33,13 @@ import org.springframework.util.ClassUtils;
|
|||
* @author Dave Syer
|
||||
*/
|
||||
public class LiquibaseServiceLocatorApplicationListener
|
||||
implements ApplicationListener<ApplicationStartedEvent> {
|
||||
implements ApplicationListener<ApplicationStartingEvent> {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(LiquibaseServiceLocatorApplicationListener.class);
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
public void onApplicationEvent(ApplicationStartingEvent event) {
|
||||
if (ClassUtils.isPresent("liquibase.servicelocator.ServiceLocator", null)) {
|
||||
new LiquibasePresent().replaceServiceLocator();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.boot.bind.RelaxedPropertyResolver;
|
|||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
@ -161,7 +161,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
LOG_LEVEL_LOGGERS.add(LogLevel.DEBUG, "org.hibernate.SQL");
|
||||
}
|
||||
|
||||
private static Class<?>[] EVENT_TYPES = { ApplicationStartedEvent.class,
|
||||
private static Class<?>[] EVENT_TYPES = { ApplicationStartingEvent.class,
|
||||
ApplicationEnvironmentPreparedEvent.class, ApplicationPreparedEvent.class,
|
||||
ContextClosedEvent.class };
|
||||
|
||||
|
@ -201,8 +201,8 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ApplicationStartedEvent) {
|
||||
onApplicationStartedEvent((ApplicationStartedEvent) event);
|
||||
if (event instanceof ApplicationStartingEvent) {
|
||||
onApplicationStartingEvent((ApplicationStartingEvent) event);
|
||||
}
|
||||
else if (event instanceof ApplicationEnvironmentPreparedEvent) {
|
||||
onApplicationEnvironmentPreparedEvent(
|
||||
|
@ -220,7 +220,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void onApplicationStartedEvent(ApplicationStartedEvent event) {
|
||||
private void onApplicationStartingEvent(ApplicationStartingEvent event) {
|
||||
this.loggingSystem = LoggingSystem
|
||||
.get(event.getSpringApplication().getClassLoader());
|
||||
this.loggingSystem.beforeInitialize();
|
||||
|
|
|
@ -44,7 +44,7 @@ import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletCon
|
|||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.testutil.InternalOutputCapture;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
@ -302,6 +302,7 @@ public class SpringApplicationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void eventsOrder() {
|
||||
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
||||
application.setWebEnvironment(false);
|
||||
|
@ -316,7 +317,9 @@ public class SpringApplicationTests {
|
|||
application.addListeners(new ApplicationRunningEventListener());
|
||||
this.context = application.run();
|
||||
assertThat(events).hasSize(5);
|
||||
assertThat(events.get(0)).isInstanceOf(ApplicationStartedEvent.class);
|
||||
assertThat(events.get(0)).isInstanceOf(
|
||||
org.springframework.boot.context.event.ApplicationStartedEvent.class);
|
||||
assertThat(events.get(0)).isInstanceOf(ApplicationStartingEvent.class);
|
||||
assertThat(events.get(1)).isInstanceOf(ApplicationEnvironmentPreparedEvent.class);
|
||||
assertThat(events.get(2)).isInstanceOf(ApplicationPreparedEvent.class);
|
||||
assertThat(events.get(3)).isInstanceOf(ContextRefreshedEvent.class);
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.testutil.InternalOutputCapture;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
@ -56,16 +56,18 @@ public class LoggingApplicationListenerIntegrationTests {
|
|||
@Test
|
||||
public void loggingPerformedDuringChildApplicationStartIsNotLost() {
|
||||
new SpringApplicationBuilder(Config.class).web(false).child(Config.class)
|
||||
.web(false).listeners(new ApplicationListener<ApplicationStartedEvent>() {
|
||||
.web(false)
|
||||
.listeners(new ApplicationListener<ApplicationStartingEvent>() {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
this.logger.info("Child application started");
|
||||
public void onApplicationEvent(ApplicationStartingEvent event) {
|
||||
this.logger.info("Child application starting");
|
||||
}
|
||||
|
||||
}).run();
|
||||
assertThat(this.outputCapture.toString()).contains("Child application started");
|
||||
assertThat(this.outputCapture.toString()).contains("Child application starting");
|
||||
}
|
||||
|
||||
@Component
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.slf4j.bridge.SLF4JBridgeHandler;
|
|||
import org.springframework.boot.ApplicationPid;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.event.ApplicationFailedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.logging.java.JavaLoggingSystem;
|
||||
import org.springframework.boot.testutil.InternalOutputCapture;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
|
@ -86,7 +86,7 @@ public class LoggingApplicationListenerTests {
|
|||
LogManager.getLogManager().readConfiguration(
|
||||
JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
|
||||
this.initializer.onApplicationEvent(
|
||||
new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
|
||||
new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
|
||||
new File("target/foo.log").delete();
|
||||
new File(tmpDir() + "/spring.log").delete();
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ public class LoggingApplicationListenerTests {
|
|||
public void parseArgsDoesntReplace() throws Exception {
|
||||
this.initializer.setSpringBootLogging(LogLevel.ERROR);
|
||||
this.initializer.setParseArgs(false);
|
||||
this.initializer.onApplicationEvent(new ApplicationStartedEvent(
|
||||
this.initializer.onApplicationEvent(new ApplicationStartingEvent(
|
||||
this.springApplication, new String[] { "--debug" }));
|
||||
this.initializer.initialize(this.context.getEnvironment(),
|
||||
this.context.getClassLoader());
|
||||
|
@ -387,7 +387,7 @@ public class LoggingApplicationListenerTests {
|
|||
System.setProperty(LoggingSystem.class.getName(),
|
||||
TestShutdownHandlerLoggingSystem.class.getName());
|
||||
listener.onApplicationEvent(
|
||||
new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
|
||||
new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
|
||||
listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
assertThat(listener.shutdownHook).isNull();
|
||||
}
|
||||
|
@ -400,7 +400,7 @@ public class LoggingApplicationListenerTests {
|
|||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
|
||||
"logging.register_shutdown_hook=true");
|
||||
listener.onApplicationEvent(
|
||||
new ApplicationStartedEvent(new SpringApplication(), NO_ARGS));
|
||||
new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
|
||||
listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
assertThat(listener.shutdownHook).isNotNull();
|
||||
listener.shutdownHook.start();
|
||||
|
@ -413,7 +413,7 @@ public class LoggingApplicationListenerTests {
|
|||
System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
|
||||
TestCleanupLoggingSystem.class.getName());
|
||||
this.initializer.onApplicationEvent(
|
||||
new ApplicationStartedEvent(this.springApplication, new String[0]));
|
||||
new ApplicationStartingEvent(this.springApplication, new String[0]));
|
||||
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
|
||||
.getField(this.initializer, "loggingSystem");
|
||||
assertThat(loggingSystem.cleanedUp).isFalse();
|
||||
|
@ -426,7 +426,7 @@ public class LoggingApplicationListenerTests {
|
|||
System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
|
||||
TestCleanupLoggingSystem.class.getName());
|
||||
this.initializer.onApplicationEvent(
|
||||
new ApplicationStartedEvent(this.springApplication, new String[0]));
|
||||
new ApplicationStartingEvent(this.springApplication, new String[0]));
|
||||
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
|
||||
.getField(this.initializer, "loggingSystem");
|
||||
assertThat(loggingSystem.cleanedUp).isFalse();
|
||||
|
@ -472,7 +472,7 @@ public class LoggingApplicationListenerTests {
|
|||
System.setProperty(LoggingSystem.SYSTEM_PROPERTY,
|
||||
TestCleanupLoggingSystem.class.getName());
|
||||
this.initializer.onApplicationEvent(
|
||||
new ApplicationStartedEvent(this.springApplication, new String[0]));
|
||||
new ApplicationStartingEvent(this.springApplication, new String[0]));
|
||||
TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
|
||||
.getField(this.initializer, "loggingSystem");
|
||||
assertThat(loggingSystem.cleanedUp).isFalse();
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.context.event.SpringApplicationEvent;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
@ -129,9 +129,9 @@ public class ApplicationPidFileWriterTests {
|
|||
public void withNoEnvironment() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
|
||||
listener.setTriggerEventType(ApplicationStartedEvent.class);
|
||||
listener.setTriggerEventType(ApplicationStartingEvent.class);
|
||||
listener.onApplicationEvent(
|
||||
new ApplicationStartedEvent(new SpringApplication(), new String[] {}));
|
||||
new ApplicationStartingEvent(new SpringApplication(), new String[] {}));
|
||||
assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue