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