org.springframework.boot.builder.SpringApplicationBuilder Maven / Gradle / Ivy
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.builder;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ResourceLoader;
/**
* Builder for {@link SpringApplication} and {@link ApplicationContext} instances with
* convenient fluent API and context hierarchy support. Simple example of a context
* hierarchy:
*
*
* new SpringApplicationBuilder(ParentConfig.class).child(ChildConfig.class).run(args);
*
*
* Another common use case is setting default arguments, e.g. active Spring profiles, to
* set up the environment for an application:
*
*
* new SpringApplicationBuilder(Application.class).profiles("server")
* .defaultArgs("--transport=local").run(args);
*
*
*
* If your needs are simpler, consider using the static convenience methods in
* SpringApplication instead.
*
* @author Dave Syer
* @author Andy Wilkinson
*/
public class SpringApplicationBuilder {
private final SpringApplication application;
private ConfigurableApplicationContext context;
private SpringApplicationBuilder parent;
private final AtomicBoolean running = new AtomicBoolean(false);
private final Set