Merge branch '1.2.x'
This commit is contained in:
commit
d46cf8e82e
|
@ -226,21 +226,12 @@ public class SpringApplication {
|
|||
if (sources != null && sources.length > 0) {
|
||||
this.sources.addAll(Arrays.asList(sources));
|
||||
}
|
||||
this.webEnvironment = deduceWebEnvironment();
|
||||
this.webEnvironment = isSpringWebAvailable();
|
||||
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();
|
||||
|
@ -886,7 +877,8 @@ public class SpringApplication {
|
|||
public void setApplicationContextClass(
|
||||
Class<? extends ConfigurableApplicationContext> applicationContextClass) {
|
||||
this.applicationContextClass = applicationContextClass;
|
||||
if (!WebApplicationContext.class.isAssignableFrom(applicationContextClass)) {
|
||||
if (isSpringWebAvailable() && !WebApplicationContext.class.isAssignableFrom(
|
||||
applicationContextClass)) {
|
||||
this.webEnvironment = false;
|
||||
}
|
||||
}
|
||||
|
@ -949,6 +941,15 @@ 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.
|
||||
|
|
Loading…
Reference in New Issue