/*
* Copyright 2012-2020 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
*
* https://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;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.SpringFactoriesLoader;
Listener for the SpringApplication
run
method. SpringApplicationRunListener
s are loaded via the SpringFactoriesLoader
and should declare a public constructor that accepts a SpringApplication
instance and a String[]
of arguments. A new SpringApplicationRunListener
instance will be created for each run. Author: Phillip Webb, Dave Syer, Andy Wilkinson Since: 1.0.0
/**
* Listener for the {@link SpringApplication} {@code run} method.
* {@link SpringApplicationRunListener}s are loaded via the {@link SpringFactoriesLoader}
* and should declare a public constructor that accepts a {@link SpringApplication}
* instance and a {@code String[]} of arguments. A new
* {@link SpringApplicationRunListener} instance will be created for each run.
*
* @author Phillip Webb
* @author Dave Syer
* @author Andy Wilkinson
* @since 1.0.0
*/
public interface SpringApplicationRunListener {
Called immediately when the run method has first started. Can be used for very
early initialization.
Params: - bootstrapContext – the bootstrap context
/**
* Called immediately when the run method has first started. Can be used for very
* early initialization.
* @param bootstrapContext the bootstrap context
*/
default void starting(ConfigurableBootstrapContext bootstrapContext) {
starting();
}
Called immediately when the run method has first started. Can be used for very
early initialization.
Deprecated: since 2.4.0 in favor of starting(ConfigurableBootstrapContext)
/**
* Called immediately when the run method has first started. Can be used for very
* early initialization.
* @deprecated since 2.4.0 in favor of {@link #starting(ConfigurableBootstrapContext)}
*/
@Deprecated
default void starting() {
}
Called once the environment has been prepared, but before the ApplicationContext
has been created. Params: - bootstrapContext – the bootstrap context
- environment – the environment
/**
* Called once the environment has been prepared, but before the
* {@link ApplicationContext} has been created.
* @param bootstrapContext the bootstrap context
* @param environment the environment
*/
default void environmentPrepared(ConfigurableBootstrapContext bootstrapContext,
ConfigurableEnvironment environment) {
environmentPrepared(environment);
}
Called once the environment has been prepared, but before the ApplicationContext
has been created. Params: - environment – the environment
Deprecated: since 2.4.0 in favor of environmentPrepared(ConfigurableBootstrapContext, ConfigurableEnvironment)
/**
* Called once the environment has been prepared, but before the
* {@link ApplicationContext} has been created.
* @param environment the environment
* @deprecated since 2.4.0 in favor of
* {@link #environmentPrepared(ConfigurableBootstrapContext, ConfigurableEnvironment)}
*/
@Deprecated
default void environmentPrepared(ConfigurableEnvironment environment) {
}
Called once the ApplicationContext
has been created and prepared, but before sources have been loaded. Params: - context – the application context
/**
* Called once the {@link ApplicationContext} has been created and prepared, but
* before sources have been loaded.
* @param context the application context
*/
default void contextPrepared(ConfigurableApplicationContext context) {
}
Called once the application context has been loaded but before it has been
refreshed.
Params: - context – the application context
/**
* Called once the application context has been loaded but before it has been
* refreshed.
* @param context the application context
*/
default void contextLoaded(ConfigurableApplicationContext context) {
}
The context has been refreshed and the application has started but CommandLineRunners
and
ApplicationRunners
have not been called. Params: - context – the application context.
Since: 2.0.0
/**
* The context has been refreshed and the application has started but
* {@link CommandLineRunner CommandLineRunners} and {@link ApplicationRunner
* ApplicationRunners} have not been called.
* @param context the application context.
* @since 2.0.0
*/
default void started(ConfigurableApplicationContext context) {
}
Called immediately before the run method finishes, when the application context has been refreshed and all CommandLineRunners
and ApplicationRunners
have been called. Params: - context – the application context.
Since: 2.0.0
/**
* Called immediately before the run method finishes, when the application context has
* been refreshed and all {@link CommandLineRunner CommandLineRunners} and
* {@link ApplicationRunner ApplicationRunners} have been called.
* @param context the application context.
* @since 2.0.0
*/
default void running(ConfigurableApplicationContext context) {
}
Called when a failure occurs when running the application.
Params: - context – the application context or
null
if a failure occurred before the context was created - exception – the failure
Since: 2.0.0
/**
* Called when a failure occurs when running the application.
* @param context the application context or {@code null} if a failure occurred before
* the context was created
* @param exception the failure
* @since 2.0.0
*/
default void failed(ConfigurableApplicationContext context, Throwable exception) {
}
}