Rename SpringApplication Events

Move SpringApplication events to their own package, create a common
base class and rename classes to match Spring conventions.
This commit is contained in:
Phillip Webb 2014-01-31 10:59:57 -08:00
parent 818326d820
commit 92f01cf9bc
23 changed files with 170 additions and 184 deletions

View File

@ -20,9 +20,9 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplicationErrorEvent;
import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcome;
import org.springframework.boot.autoconfigure.AutoConfigurationReport.ConditionAndOutcomes;
import org.springframework.boot.event.ApplicationFailedEvent;
import org.springframework.boot.logging.LogLevel;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEvent;
@ -76,7 +76,7 @@ public class AutoConfigurationReportLoggingInitializer implements
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> type) {
return ContextRefreshedEvent.class.isAssignableFrom(type)
|| SpringApplicationErrorEvent.class.isAssignableFrom(type);
|| ApplicationFailedEvent.class.isAssignableFrom(type);
}
@Override
@ -91,8 +91,8 @@ public class AutoConfigurationReportLoggingInitializer implements
logAutoConfigurationReport();
}
}
else if (event instanceof SpringApplicationErrorEvent) {
if (((SpringApplicationErrorEvent) event).getApplicationContext() == this.applicationContext) {
else if (event instanceof ApplicationFailedEvent) {
if (((ApplicationFailedEvent) event).getApplicationContext() == this.applicationContext) {
logAutoConfigurationReport(true);
}
}

View File

@ -30,9 +30,9 @@ import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationErrorEvent;
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.event.ApplicationFailedEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -127,8 +127,8 @@ public class AutoConfigurationReportLoggingInitializerTests {
fail("Did not error");
}
catch (Exception ex) {
this.initializer.onApplicationEvent(new SpringApplicationErrorEvent(
new SpringApplication(), context, new String[] {}, ex));
this.initializer.onApplicationEvent(new ApplicationFailedEvent(
new SpringApplication(), new String[0], context, ex));
}
assertThat(this.debugLog.size(), not(equalTo(0)));
@ -146,8 +146,8 @@ public class AutoConfigurationReportLoggingInitializerTests {
fail("Did not error");
}
catch (Exception ex) {
this.initializer.onApplicationEvent(new SpringApplicationErrorEvent(
new SpringApplication(), context, new String[] {}, ex));
this.initializer.onApplicationEvent(new ApplicationFailedEvent(
new SpringApplication(), new String[0], context, ex));
}
assertThat(this.debugLog.size(), equalTo(0));
@ -190,8 +190,8 @@ public class AutoConfigurationReportLoggingInitializerTests {
@Test
public void noErrorIfNotInitialized() throws Exception {
this.initializer.onApplicationEvent(new SpringApplicationErrorEvent(
new SpringApplication(), null, new String[0], new RuntimeException(
this.initializer.onApplicationEvent(new ApplicationFailedEvent(
new SpringApplication(), new String[0], null, new RuntimeException(
"Planned")));
assertThat(this.infoLog.get(0),
containsString("Unable to provide auto-configuration report"));

View File

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.security;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationBeforeRefreshEvent;
import org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializer;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
@ -26,6 +25,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.context.listener.LoggingApplicationListener;
import org.springframework.boot.event.ApplicationPreparedEvent;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -119,8 +119,8 @@ public class SecurityAutoConfigurationTests {
AnnotationConfigWebApplicationContext context) {
EnvironmentTestUtils.addEnvironment(context, "debug:true");
LoggingApplicationListener logging = new LoggingApplicationListener();
logging.onApplicationEvent(new SpringApplicationBeforeRefreshEvent(
new SpringApplication(), context, new String[0]));
logging.onApplicationEvent(new ApplicationPreparedEvent(new SpringApplication(),
new String[0], context));
AutoConfigurationReportLoggingInitializer initializer = new AutoConfigurationReportLoggingInitializer();
initializer.initialize(context);
context.refresh();

View File

@ -36,6 +36,10 @@ import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.event.ApplicationFailedEvent;
import org.springframework.boot.event.ApplicationPreparedEvent;
import org.springframework.boot.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationEvent;
@ -313,8 +317,9 @@ public class SpringApplication {
try {
Set<Object> sources = getSources();
registerListeners(multicaster, sources);
// Allow logging and stuff to initialize very early
multicaster.multicastEvent(new SpringApplicationStartEvent(this, args));
multicaster.multicastEvent(new ApplicationStartedEvent(this, args));
// Create and configure the environment
ConfigurableEnvironment environment = getOrCreateEnvironment();
@ -324,12 +329,13 @@ public class SpringApplication {
}
// Notify listeners of the environment creation
multicaster.multicastEvent(new SpringApplicationEnvironmentAvailableEvent(
this, environment, args));
multicaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(this,
args, environment));
// Sources might have changed when environment was applied
sources = getSources();
Assert.notEmpty(sources, "Sources must not be empty");
if (this.showBanner) {
printBanner();
}
@ -349,9 +355,10 @@ public class SpringApplication {
}
load(context, sources.toArray(new Object[sources.size()]));
// Notify listeners of intention to refresh
multicaster.multicastEvent(new SpringApplicationBeforeRefreshEvent(this,
context, args));
multicaster.multicastEvent(new ApplicationPreparedEvent(this, args, context));
refresh(context);
stopWatch.stop();
@ -364,21 +371,21 @@ public class SpringApplication {
return context;
}
catch (RuntimeException ex) {
handleError(context, multicaster, ex, args);
handleFailure(context, multicaster, ex, args);
throw ex;
}
catch (Error ex) {
handleError(context, multicaster, ex, args);
handleFailure(context, multicaster, ex, args);
throw ex;
}
}
protected void handleError(ConfigurableApplicationContext context,
protected void handleFailure(ConfigurableApplicationContext context,
ApplicationEventMulticaster multicaster, Throwable exception, String... args) {
try {
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context,
args, exception));
multicaster.multicastEvent(new ApplicationFailedEvent(this, args, context,
exception));
}
catch (Exception ex) {
// We don't want to fail here and mask the original exception
@ -1024,7 +1031,7 @@ public class SpringApplication {
ApplicationEvent event) {
List<ApplicationListener<?>> listeners = new ArrayList<ApplicationListener<?>>();
listeners.addAll(super.getApplicationListeners(event));
if (event instanceof SpringApplicationErrorEvent) {
if (event instanceof ApplicationFailedEvent) {
Collections.reverse(listeners);
}
return listeners;

View File

@ -21,16 +21,16 @@ import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplicationErrorEvent;
import org.springframework.boot.SpringApplicationStartEvent;
import org.springframework.boot.event.ApplicationFailedEvent;
import org.springframework.boot.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
/**
* A {@link SmartApplicationListener} that reacts to {@link SpringApplicationStartEvent
* start events} by logging the classpath of the thread context class loader (TCCL) at
* {@code DEBUG} level and to {@link SpringApplicationErrorEvent error events} by logging
* the TCCL's classpath at {@code INFO} level.
* A {@link SmartApplicationListener} that reacts to {@link ApplicationStartedEvent start
* events} by logging the classpath of the thread context class loader (TCCL) at
* {@code DEBUG} level and to {@link ApplicationFailedEvent error events} by logging the
* TCCL's classpath at {@code INFO} level.
*
* @author Andy Wilkinson
*/
@ -43,13 +43,13 @@ public final class ClasspathLoggingApplicationListener implements
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof SpringApplicationStartEvent) {
if (event instanceof ApplicationStartedEvent) {
if (this.logger.isDebugEnabled()) {
this.logger
.debug("Application started with classpath: " + getClasspath());
}
}
else if (event instanceof SpringApplicationErrorEvent) {
else if (event instanceof ApplicationFailedEvent) {
if (this.logger.isInfoEnabled()) {
this.logger.info("Application failed to start with classpath: "
+ getClasspath());
@ -64,8 +64,8 @@ public final class ClasspathLoggingApplicationListener implements
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> type) {
return SpringApplicationStartEvent.class.isAssignableFrom(type)
|| SpringApplicationErrorEvent.class.isAssignableFrom(type);
return ApplicationStartedEvent.class.isAssignableFrom(type)
|| ApplicationFailedEvent.class.isAssignableFrom(type);
}
@Override

View File

@ -31,12 +31,12 @@ import java.util.Set;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.bind.PropertySourcesPropertyValues;
import org.springframework.boot.bind.RelaxedDataBinder;
import org.springframework.boot.config.DefaultPropertySourceLoadersFactory;
import org.springframework.boot.config.PropertySourceLoader;
import org.springframework.boot.config.PropertySourceLoadersFactory;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.PropertySources;
@ -81,7 +81,7 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb
*/
public class ConfigFileApplicationListener implements
ApplicationListener<SpringApplicationEnvironmentAvailableEvent>, Ordered {
ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
private static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";
@ -110,7 +110,7 @@ public class ConfigFileApplicationListener implements
* ("spring.main.show_banner=false").
*/
@Override
public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event) {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
Environment environment = event.getEnvironment();
if (environment instanceof ConfigurableEnvironment) {
configure((ConfigurableEnvironment) environment, event.getSpringApplication());

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
@ -52,8 +52,8 @@ public class EnvironmentDelegateApplicationListener implements
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof SpringApplicationEnvironmentAvailableEvent) {
List<ApplicationListener<ApplicationEvent>> delegates = getListeners(((SpringApplicationEnvironmentAvailableEvent) event)
if (event instanceof ApplicationEnvironmentPreparedEvent) {
List<ApplicationListener<ApplicationEvent>> delegates = getListeners(((ApplicationEnvironmentPreparedEvent) event)
.getEnvironment());
if (delegates.isEmpty()) {
return;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -18,8 +18,8 @@ package org.springframework.boot.context.listener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
/**
@ -42,12 +42,12 @@ import org.springframework.context.ApplicationListener;
* @author Dave Syer
*/
public class FileEncodingApplicationListener implements
ApplicationListener<SpringApplicationEnvironmentAvailableEvent> {
ApplicationListener<ApplicationEnvironmentPreparedEvent> {
private static Log logger = LogFactory.getLog(FileEncodingApplicationListener.class);
@Override
public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event) {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
event.getEnvironment(), "spring.");
if (resolver.containsProperty("mandatoryFileEncoding")) {

View File

@ -26,8 +26,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.SpringApplicationStartEvent;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.event.ApplicationStartedEvent;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.context.ApplicationEvent;
@ -94,9 +94,8 @@ public class LoggingApplicationListener implements SmartApplicationListener {
@SuppressWarnings("unchecked")
private static Collection<Class<? extends ApplicationEvent>> EVENT_TYPES = Arrays
.<Class<? extends ApplicationEvent>> asList(
SpringApplicationStartEvent.class,
SpringApplicationEnvironmentAvailableEvent.class);
.<Class<? extends ApplicationEvent>> asList(ApplicationStartedEvent.class,
ApplicationEnvironmentPreparedEvent.class);
private final Log logger = LogFactory.getLog(getClass());
@ -123,8 +122,8 @@ public class LoggingApplicationListener implements SmartApplicationListener {
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof SpringApplicationEnvironmentAvailableEvent) {
SpringApplicationEnvironmentAvailableEvent available = (SpringApplicationEnvironmentAvailableEvent) event;
if (event instanceof ApplicationEnvironmentPreparedEvent) {
ApplicationEnvironmentPreparedEvent available = (ApplicationEnvironmentPreparedEvent) event;
initialize(available.getEnvironment(), available.getSpringApplication()
.getClassLoader());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2014 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.
@ -26,9 +26,9 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.config.JsonParser;
import org.springframework.boot.config.JsonParserFactory;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.env.CommandLinePropertySource;
@ -88,7 +88,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
*/
public class VcapApplicationListener implements
ApplicationListener<SpringApplicationEnvironmentAvailableEvent>, Ordered {
ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
private static final Log logger = LogFactory.getLog(VcapApplicationListener.class);
@ -112,7 +112,7 @@ public class VcapApplicationListener implements
}
@Override
public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event) {
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
if (!environment.containsProperty(VCAP_APPLICATION)

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.event;
import org.springframework.context.ApplicationEvent;
import org.springframework.boot.SpringApplication;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
@ -26,36 +26,19 @@ import org.springframework.core.env.Environment;
*
* @author Dave Syer
*/
public class SpringApplicationEnvironmentAvailableEvent extends ApplicationEvent {
public class ApplicationEnvironmentPreparedEvent extends SpringApplicationEvent {
private final ConfigurableEnvironment environment;
private final String[] args;
/**
* @param springApplication the current application
* @param environment the environment that was just created
* @param application the current application
* @param args the argumemts the application is running with
* @param environment the environment that was just created
*/
public SpringApplicationEnvironmentAvailableEvent(
SpringApplication springApplication, ConfigurableEnvironment environment,
String[] args) {
super(springApplication);
public ApplicationEnvironmentPreparedEvent(SpringApplication application,
String[] args, ConfigurableEnvironment environment) {
super(application, args);
this.environment = environment;
this.args = args;
}
/**
* @return the springApplication
*/
public SpringApplication getSpringApplication() {
return (SpringApplication) getSource();
}
/**
* @return the args
*/
public String[] getArgs() {
return this.args;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -14,9 +14,9 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.event;
import org.springframework.context.ApplicationEvent;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
/**
@ -24,23 +24,22 @@ import org.springframework.context.ConfigurableApplicationContext;
*
* @author Dave Syer
*/
public class SpringApplicationErrorEvent extends ApplicationEvent {
public class ApplicationFailedEvent extends SpringApplicationEvent {
private final String[] args;
private final Throwable exception;
private final ConfigurableApplicationContext context;
private final Throwable exception;
/**
* @param springApplication the current application
* @param application the current application
* @param context the context that was being created (maybe null)
* @param args the arguments the application was running with
* @param exception the exception that caused the error
*/
public SpringApplicationErrorEvent(SpringApplication springApplication,
ConfigurableApplicationContext context, String[] args, Throwable exception) {
super(springApplication);
public ApplicationFailedEvent(SpringApplication application, String[] args,
ConfigurableApplicationContext context, Throwable exception) {
super(application, args);
this.context = context;
this.args = args;
this.exception = exception;
}
@ -51,13 +50,6 @@ public class SpringApplicationErrorEvent extends ApplicationEvent {
return this.context;
}
/**
* @return the springApplication
*/
public SpringApplication getSpringApplication() {
return (SpringApplication) getSource();
}
/**
* @return the exception
*/
@ -65,11 +57,4 @@ public class SpringApplicationErrorEvent extends ApplicationEvent {
return this.exception;
}
/**
* @return the args
*/
public String[] getArgs() {
return this.args;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -14,49 +14,33 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.event;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
/**
* Event published as when a {@link SpringApplication} is starting up and the
* {@link ApplicationContext} is about to refresh. The bean definitions will be loaded and
* the {@link Environment} is ready for use at this stage.
* {@link ApplicationContext} is fully prepared but not refreshed. The bean definitions
* will be loaded and the {@link Environment} is ready for use at this stage.
*
* @author Dave Syer
*/
public class SpringApplicationBeforeRefreshEvent extends ApplicationEvent {
public class ApplicationPreparedEvent extends SpringApplicationEvent {
private final String[] args;
private final ConfigurableApplicationContext context;
/**
* @param springApplication the current application
* @param context the ApplicationContext about to be refreshed
* @param application the current application
* @param args the argumemts the application is running with
* @param context the ApplicationContext about to be refreshed
*/
public SpringApplicationBeforeRefreshEvent(SpringApplication springApplication,
ConfigurableApplicationContext context, String[] args) {
super(springApplication);
public ApplicationPreparedEvent(SpringApplication application, String[] args,
ConfigurableApplicationContext context) {
super(application, args);
this.context = context;
this.args = args;
}
/**
* @return the springApplication
*/
public SpringApplication getSpringApplication() {
return (SpringApplication) getSource();
}
/**
* @return the args
*/
public String[] getArgs() {
return this.args;
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -14,10 +14,10 @@
* limitations under the License.
*/
package org.springframework.boot;
package org.springframework.boot.event;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
@ -30,31 +30,14 @@ import org.springframework.core.env.Environment;
*
* @author Dave Syer
*/
public class SpringApplicationStartEvent extends ApplicationEvent {
private final String[] args;
public class ApplicationStartedEvent extends SpringApplicationEvent {
/**
* @param springApplication the current application
* @param application the current application
* @param args the argumemts the application is running with
*/
public SpringApplicationStartEvent(SpringApplication springApplication, String[] args) {
super(springApplication);
this.args = args;
}
/**
* @return the springApplication
*/
public SpringApplication getSpringApplication() {
return (SpringApplication) getSource();
}
/**
* @return the args
*/
public String[] getArgs() {
return this.args;
public ApplicationStartedEvent(SpringApplication application, String[] args) {
super(application, args);
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2012-2014 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.event;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationEvent;
/**
* Base class for {@link ApplicationEvent} related to a {@link SpringApplication}.
*
* @author Phillip Webb
*/
public abstract class SpringApplicationEvent extends ApplicationEvent {
private final String[] args;
public SpringApplicationEvent(SpringApplication application, String[] args) {
super(application);
this.args = args;
}
public SpringApplication getSpringApplication() {
return (SpringApplication) getSource();
}
public final String[] getArgs() {
return this.args;
}
}

View File

@ -5,7 +5,7 @@ import liquibase.servicelocator.ServiceLocator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplicationStartEvent;
import org.springframework.boot.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.util.ClassUtils;
@ -17,12 +17,12 @@ import org.springframework.util.ClassUtils;
* @author Dave Syer
*/
public class LiquibaseServiceLocatorInitializer implements
ApplicationListener<SpringApplicationStartEvent> {
ApplicationListener<ApplicationStartedEvent> {
static final Log logger = LogFactory.getLog(LiquibaseServiceLocatorInitializer.class);
@Override
public void onApplicationEvent(SpringApplicationStartEvent event) {
public void onApplicationEvent(ApplicationStartedEvent event) {
if (ClassUtils.isPresent("liquibase.servicelocator.ServiceLocator", null)) {
new LiquibasePresent().replaceServiceLocator();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -41,7 +41,8 @@ public class ServletListenerRegistrationBeanTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private final ServletContextListener listener = Mockito.mock(ServletContextListener.class);
private final ServletContextListener listener = Mockito
.mock(ServletContextListener.class);
@Mock
private ServletContext servletContext;

View File

@ -24,9 +24,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.config.PropertySourceLoader;
import org.springframework.boot.config.PropertySourceLoadersFactory;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@ -56,8 +56,8 @@ public class ConfigFileApplicationListenerTests {
private final StandardEnvironment environment = new StandardEnvironment();
private final SpringApplicationEnvironmentAvailableEvent event = new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.environment, new String[0]);
private final ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.environment);
private final ConfigFileApplicationListener initializer = new ConfigFileApplicationListener();

View File

@ -21,7 +21,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
@ -53,8 +53,8 @@ public class EnvironmentDelegateApplicationListenerTests {
public void orderedInitialize() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "context.listener.classes:"
+ MockInitB.class.getName() + "," + MockInitA.class.getName());
this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0]));
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.context.getEnvironment()));
this.context.getBeanFactory().registerSingleton("testListener", this.listener);
this.context.refresh();
assertThat(this.context.getBeanFactory().getSingleton("a"), equalTo((Object) "a"));
@ -63,15 +63,15 @@ public class EnvironmentDelegateApplicationListenerTests {
@Test
public void noInitializers() throws Exception {
this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0]));
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.context.getEnvironment()));
}
@Test
public void emptyInitializers() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "context.listener.classes:");
this.listener.onApplicationEvent(new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0]));
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.context.getEnvironment()));
}
@Order(Ordered.HIGHEST_PRECEDENCE)

View File

@ -19,7 +19,7 @@ package org.springframework.boot.context.listener;
import org.junit.Assume;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
@ -33,8 +33,8 @@ public class FileEncodingApplicationListenerTests {
private final FileEncodingApplicationListener initializer = new FileEncodingApplicationListener();
private final ConfigurableEnvironment environment = new StandardEnvironment();
private final SpringApplicationEnvironmentAvailableEvent event = new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.environment, new String[0]);
private final ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.environment);
@Test(expected = IllegalStateException.class)
public void testIllegalState() {

View File

@ -29,7 +29,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationStartEvent;
import org.springframework.boot.event.ApplicationStartedEvent;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.java.JavaLoggingSystem;
import org.springframework.boot.test.EnvironmentTestUtils;
@ -70,7 +70,7 @@ public class LoggingApplicationListenerTests {
public void init() throws SecurityException, IOException {
LogManager.getLogManager().readConfiguration(
JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
this.initializer.onApplicationEvent(new SpringApplicationStartEvent(
this.initializer.onApplicationEvent(new ApplicationStartedEvent(
new SpringApplication(), NO_ARGS));
new File("target/foo.log").delete();
}
@ -190,7 +190,7 @@ public class LoggingApplicationListenerTests {
public void parseArgsDoesntReplace() throws Exception {
this.initializer.setSpringBootLogging(LogLevel.ERROR);
this.initializer.setParseArgs(false);
this.initializer.onApplicationEvent(new SpringApplicationStartEvent(
this.initializer.onApplicationEvent(new ApplicationStartedEvent(
this.springApplication, new String[] { "--debug" }));
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());

View File

@ -18,7 +18,7 @@ package org.springframework.boot.context.listener;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationEnvironmentAvailableEvent;
import org.springframework.boot.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -34,8 +34,8 @@ public class VcapApplicationListenerTests {
private final VcapApplicationListener initializer = new VcapApplicationListener();
private final ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
private final SpringApplicationEnvironmentAvailableEvent event = new SpringApplicationEnvironmentAvailableEvent(
new SpringApplication(), this.context.getEnvironment(), new String[0]);
private final ApplicationEnvironmentPreparedEvent event = new ApplicationEnvironmentPreparedEvent(
new SpringApplication(), new String[0], this.context.getEnvironment());
@Test
public void testApplicationProperties() {

View File

@ -40,8 +40,8 @@ public class LogbackLoggingSystemTests {
@Rule
public OutputCapture output = new OutputCapture();
private final LogbackLoggingSystem loggingSystem = new LogbackLoggingSystem(getClass()
.getClassLoader());
private final LogbackLoggingSystem loggingSystem = new LogbackLoggingSystem(
getClass().getClassLoader());
private Log logger;