|
|
@ -49,6 +49,7 @@ import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
|
|
|
import org.springframework.context.support.AbstractApplicationContext;
|
|
|
|
import org.springframework.context.support.AbstractApplicationContext;
|
|
|
|
import org.springframework.context.support.GenericApplicationContext;
|
|
|
|
import org.springframework.context.support.GenericApplicationContext;
|
|
|
|
import org.springframework.core.GenericTypeResolver;
|
|
|
|
import org.springframework.core.GenericTypeResolver;
|
|
|
|
|
|
|
|
import org.springframework.core.OrderComparator;
|
|
|
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
|
|
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
|
|
|
import org.springframework.core.env.CommandLinePropertySource;
|
|
|
|
import org.springframework.core.env.CommandLinePropertySource;
|
|
|
|
import org.springframework.core.env.CompositePropertySource;
|
|
|
|
import org.springframework.core.env.CompositePropertySource;
|
|
|
@ -232,11 +233,32 @@ public class SpringApplication {
|
|
|
|
* {@link SpringFactoriesLoader}. Subclasses can override this method to modify
|
|
|
|
* {@link SpringFactoriesLoader}. Subclasses can override this method to modify
|
|
|
|
* default initializers if necessary.
|
|
|
|
* default initializers if necessary.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
|
|
|
|
protected Collection<ApplicationContextInitializer<?>> getSpringFactoriesApplicationContextInitializers() {
|
|
|
|
protected Collection<ApplicationContextInitializer<?>> getSpringFactoriesApplicationContextInitializers() {
|
|
|
|
return (Collection) SpringFactoriesLoader.loadFactories(
|
|
|
|
ClassLoader classLoader = SpringApplication.class.getClassLoader();
|
|
|
|
ApplicationContextInitializer.class,
|
|
|
|
|
|
|
|
SpringApplication.class.getClassLoader());
|
|
|
|
// Use names and ensure unique to protect against duplicates
|
|
|
|
|
|
|
|
Set<String> names = new LinkedHashSet<String>(
|
|
|
|
|
|
|
|
SpringFactoriesLoader.loadFactoryNames(
|
|
|
|
|
|
|
|
ApplicationContextInitializer.class, classLoader));
|
|
|
|
|
|
|
|
List<ApplicationContextInitializer<?>> factories = new ArrayList<ApplicationContextInitializer<?>>(
|
|
|
|
|
|
|
|
names.size());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create instances from the names
|
|
|
|
|
|
|
|
for (String name : names) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Class<?> instanceClass = ClassUtils.forName(name, classLoader);
|
|
|
|
|
|
|
|
Assert.isAssignable(ApplicationContextInitializer.class, instanceClass);
|
|
|
|
|
|
|
|
factories.add((ApplicationContextInitializer<?>) instanceClass
|
|
|
|
|
|
|
|
.newInstance());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable ex) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
|
|
|
|
"Cannot instantiate ApplicationContextInitializer : " + name, ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OrderComparator.sort(factories);
|
|
|
|
|
|
|
|
return factories;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Class<?> deduceMainApplicationClass() {
|
|
|
|
private Class<?> deduceMainApplicationClass() {
|
|
|
|