Java Code Examples for org.springframework.boot.SpringApplication#getInitializers()

The following examples show how to use org.springframework.boot.SpringApplication#getInitializers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BootstrapApplicationListener.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
private void addAncestorInitializer(SpringApplication application,
		ConfigurableApplicationContext context) {
	boolean installed = false;
	for (ApplicationContextInitializer<?> initializer : application
			.getInitializers()) {
		if (initializer instanceof AncestorInitializer) {
			installed = true;
			// New parent
			((AncestorInitializer) initializer).setParent(context);
		}
	}
	if (!installed) {
		application.addInitializers(new AncestorInitializer(context));
	}

}
 
Example 2
Source File: BootstrapApplicationListener.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void addBootstrapDecryptInitializer(SpringApplication application) {
	DelegatingEnvironmentDecryptApplicationInitializer decrypter = null;
	Set<ApplicationContextInitializer<?>> initializers = new LinkedHashSet<>();
	for (ApplicationContextInitializer<?> ini : application.getInitializers()) {
		if (ini instanceof EnvironmentDecryptApplicationInitializer) {
			@SuppressWarnings("rawtypes")
			ApplicationContextInitializer del = ini;
			decrypter = new DelegatingEnvironmentDecryptApplicationInitializer(del);
			initializers.add(ini);
			initializers.add(decrypter);
		}
		else if (ini instanceof DelegatingEnvironmentDecryptApplicationInitializer) {
			// do nothing
		}
		else {
			initializers.add(ini);
		}
	}
	ArrayList<ApplicationContextInitializer<?>> target = new ArrayList<ApplicationContextInitializer<?>>(
			initializers);
	application.setInitializers(target);
}
 
Example 3
Source File: BootstrapApplicationListener.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void apply(ConfigurableApplicationContext context,
		SpringApplication application, ConfigurableEnvironment environment) {
	if (application.getAllSources().contains(BootstrapMarkerConfiguration.class)) {
		return;
	}
	application.addPrimarySources(Arrays.asList(BootstrapMarkerConfiguration.class));
	@SuppressWarnings("rawtypes")
	Set target = new LinkedHashSet<>(application.getInitializers());
	target.addAll(
			getOrderedBeansOfType(context, ApplicationContextInitializer.class));
	application.setInitializers(target);
	addBootstrapDecryptInitializer(application);
}