Merge branch '1.2.x'

pull/3741/merge
Phillip Webb 9 years ago
commit f4dcef281c

@ -19,7 +19,6 @@
<properties>
<main.basedir>${basedir}/..</main.basedir>
<java.version>1.7</java.version>
<cargo.timeout>300000</cargo.timeout>
<cargo.container.download-dir>${user.home}/.cargo/installs</cargo.container.download-dir>
</properties>
@ -28,7 +27,6 @@
<module>spring-boot-deployment-test-tomcat</module>
<module>spring-boot-deployment-test-wildfly</module>
</modules>
<build>
<pluginManagement>
<plugins>
@ -74,5 +72,4 @@
</plugins>
</pluginManagement>
</build>
</project>

@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import sample.simple.service.HelloWorldService;
@ -39,6 +40,9 @@ public class SampleSimpleApplication implements CommandLineRunner {
}
public static void main(String[] args) throws Exception {
SpringApplication application = new SpringApplication(
SampleSimpleApplication.class);
application.setApplicationContextClass(AnnotationConfigApplicationContext.class);
SpringApplication.run(SampleSimpleApplication.class, args);
}

@ -226,12 +226,21 @@ public class SpringApplication {
if (sources != null && sources.length > 0) {
this.sources.addAll(Arrays.asList(sources));
}
this.webEnvironment = isSpringWebAvailable();
this.webEnvironment = deduceWebEnvironment();
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
this.mainApplicationClass = deduceMainApplicationClass();
}
private boolean deduceWebEnvironment() {
for (String className : WEB_ENVIRONMENT_CLASSES) {
if (!ClassUtils.isPresent(className, null)) {
return false;
}
}
return true;
}
private Class<?> deduceMainApplicationClass() {
try {
StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
@ -877,12 +886,20 @@ public class SpringApplication {
public void setApplicationContextClass(
Class<? extends ConfigurableApplicationContext> applicationContextClass) {
this.applicationContextClass = applicationContextClass;
if (!isSpringWebAvailable()
|| !WebApplicationContext.class.isAssignableFrom(applicationContextClass)) {
if (!isWebApplicationContext(applicationContextClass)) {
this.webEnvironment = false;
}
}
private boolean isWebApplicationContext(Class<?> applicationContextClass) {
try {
return WebApplicationContext.class.isAssignableFrom(applicationContextClass);
}
catch (NoClassDefFoundError ex) {
return false;
}
}
/**
* Sets the {@link ApplicationContextInitializer} that will be applied to the Spring
* {@link ApplicationContext}.
@ -941,15 +958,6 @@ public class SpringApplication {
return asUnmodifiableOrderedSet(this.listeners);
}
private boolean isSpringWebAvailable() {
for (String className : WEB_ENVIRONMENT_CLASSES) {
if (!ClassUtils.isPresent(className, null)) {
return false;
}
}
return true;
}
/**
* Static helper that can be used to run a {@link SpringApplication} from the
* specified source using default settings.

@ -81,6 +81,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
throws Exception {
assertValidAnnotations(config.getTestClass());
SpringApplication application = getSpringApplication();
application.setRegisterShutdownHook(false);
application.setMainApplicationClass(config.getTestClass());
application.setSources(getSources(config));
ConfigurableEnvironment environment = new StandardEnvironment();

Loading…
Cancel
Save