Package org.springframework.boot.builder
Class SpringApplicationBuilder
java.lang.Object
org.springframework.boot.builder.SpringApplicationBuilder
Builder for 
SpringApplication and 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 active profiles and default properties to set up the environment for an application:
 new SpringApplicationBuilder(Application.class).profiles("server")
                .properties("transport=local").run(args);
 
 If your needs are simpler, consider using the static convenience methods in SpringApplication instead.
- Since:
- 1.0.0
- Author:
- Dave Syer, Andy Wilkinson
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionSpringApplicationBuilder(Class<?>... sources) SpringApplicationBuilder(ResourceLoader resourceLoader, Class<?>... sources) 
- 
Method SummaryModifier and TypeMethodDescriptionaddBootstrapRegistryInitializer(BootstrapRegistryInitializer bootstrapRegistryInitializer) AddsBootstrapRegistryInitializerinstances that can be used to initialize theBootstrapRegistry.addCommandLineProperties(boolean addCommandLineProperties) Flag to indicate that command line arguments should be added to the environment.allowCircularReferences(boolean allowCircularReferences) Whether to allow circular references between beans and automatically try to resolve them.Accessor for the current application.applicationStartup(ApplicationStartup applicationStartup) Configure theApplicationStartupto be used with theApplicationContextfor collecting startup metrics.Sets theBannerinstance which will be used to print the banner when no static banner file is provided.bannerMode(Banner.Mode bannerMode) beanNameGenerator(BeanNameGenerator beanNameGenerator) Bean name generator for automatically generated bean names in the application context.build()Returns a fully configuredSpringApplicationthat is ready to run.Returns a fully configuredSpringApplicationthat is ready to run.Create a child application with the provided sources.context()Accessor for the current application context.contextFactory(ApplicationContextFactory factory) Explicitly set the factory used to create the application context.protected SpringApplicationcreateSpringApplication(ResourceLoader resourceLoader, Class<?>... sources) Creates a newSpringApplicationinstance from the given sources using the givenResourceLoader.environment(ConfigurableEnvironment environment) Environment for the application context.environmentPrefix(String environmentPrefix) Prefix that should be applied when obtaining configuration properties from the system environment.headless(boolean headless) Sets if the application is headless and should not instantiate AWT.initializers(ApplicationContextInitializer<?>... initializers) Add some initializers to the application (applied to theApplicationContextbefore any bean definitions are loaded).lazyInitialization(boolean lazyInitialization) Flag to control whether the application should be initialized lazily.listeners(ApplicationListener<?>... listeners) Add some listeners to the application (listening for SpringApplication events as well as regular Spring events once the context is running).logStartupInfo(boolean logStartupInfo) Flag to indicate the startup information should be logged.Fixes the main application class that is used to anchor the startup messages.Add a parent application with the provided sources.parent(ConfigurableApplicationContext parent) Add an already running parent context to an existing application.Add to the active Spring profiles for this app (and its parent and children).properties(String... defaultProperties) Default properties for the environment in the formkey=valueorkey:value.properties(Map<String, Object> defaults) Default properties for the environment.properties(Properties defaultProperties) Default properties for the environment.Multiple calls to this method are cumulative and will not clear any previously set properties.registerShutdownHook(boolean registerShutdownHook) Sets if the createdApplicationContextshould have a shutdown hook registered.resourceLoader(ResourceLoader resourceLoader) ResourceLoaderfor the application context.Create an application context (and its parent if specified) with the command line args provided.setAddConversionService(boolean addConversionService) Flag to indicate if theApplicationConversionServiceshould be added to the application context'sEnvironment.Create a sibling application (one with the same parent).Create a sibling application (one with the same parent).Add more sources (configuration classes and components) to this application.web(WebApplicationType webApplicationType) Flag to explicitly request a specific type of web application.
- 
Constructor Details- 
SpringApplicationBuilder
- 
SpringApplicationBuilder
 
- 
- 
Method Details- 
createSpringApplicationprotected SpringApplication createSpringApplication(ResourceLoader resourceLoader, Class<?>... sources) Creates a newSpringApplicationinstance from the given sources using the givenResourceLoader. Subclasses may override in order to provide a custom subclass ofSpringApplication.- Parameters:
- resourceLoader- the resource loader or- null
- sources- the sources
- Returns:
- the SpringApplicationinstance
- Since:
- 2.6.0
 
- 
contextAccessor for the current application context.- Returns:
- the current application context (or null if not yet running)
 
- 
applicationAccessor for the current application.- Returns:
- the current application (never null)
 
- 
runCreate an application context (and its parent if specified) with the command line args provided. The parent is run first with the same arguments if it has not yet been started.- Parameters:
- args- the command line arguments
- Returns:
- an application context created from the current state
 
- 
buildReturns a fully configuredSpringApplicationthat is ready to run.- Returns:
- the fully configured SpringApplication.
 
- 
buildReturns a fully configuredSpringApplicationthat is ready to run. Any parent that has been configured will be run with the givenargs.- Parameters:
- args- the parent's args
- Returns:
- the fully configured SpringApplication.
 
- 
childCreate a child application with the provided sources. Default args and environment are copied down into the child, but everything else is a clean sheet.- Parameters:
- sources- the sources for the application (Spring configuration)
- Returns:
- the child application builder
 
- 
parentAdd a parent application with the provided sources. Default args and environment are copied up into the parent, but everything else is a clean sheet.- Parameters:
- sources- the sources for the application (Spring configuration)
- Returns:
- the parent builder
 
- 
parentAdd an already running parent context to an existing application.- Parameters:
- parent- the parent context
- Returns:
- the current builder (not the parent)
 
- 
siblingCreate a sibling application (one with the same parent). A side effect of calling this method is that the current application (and its parent) are started without any arguments if they are not already running. To supply arguments when starting the current application and its parent usesibling(Class[], String...)instead.- Parameters:
- sources- the sources for the application (Spring configuration)
- Returns:
- the new sibling builder
 
- 
siblingCreate a sibling application (one with the same parent). A side effect of calling this method is that the current application (and its parent) are started if they are not already running.- Parameters:
- sources- the sources for the application (Spring configuration)
- args- the command line arguments to use when starting the current app and its parent
- Returns:
- the new sibling builder
 
- 
contextFactoryExplicitly set the factory used to create the application context.- Parameters:
- factory- the factory to use
- Returns:
- the current builder
- Since:
- 2.4.0
 
- 
sourcesAdd more sources (configuration classes and components) to this application.- Parameters:
- sources- the sources to add
- Returns:
- the current builder
 
- 
webFlag to explicitly request a specific type of web application. Auto-detected based on the classpath if not set.- Parameters:
- webApplicationType- the type of web application
- Returns:
- the current builder
- Since:
- 2.0.0
 
- 
logStartupInfoFlag to indicate the startup information should be logged.- Parameters:
- logStartupInfo- the flag to set. Default true.
- Returns:
- the current builder
 
- 
bannerSets theBannerinstance which will be used to print the banner when no static banner file is provided.- Parameters:
- banner- the banner to use
- Returns:
- the current builder
 
- 
bannerMode
- 
headlessSets if the application is headless and should not instantiate AWT. Defaults totrueto prevent java icons appearing.- Parameters:
- headless- if the application is headless
- Returns:
- the current builder
 
- 
registerShutdownHookSets if the createdApplicationContextshould have a shutdown hook registered.- Parameters:
- registerShutdownHook- if the shutdown hook should be registered
- Returns:
- the current builder
 
- 
mainFixes the main application class that is used to anchor the startup messages.- Parameters:
- mainApplicationClass- the class to use.
- Returns:
- the current builder
 
- 
addCommandLinePropertiesFlag to indicate that command line arguments should be added to the environment.- Parameters:
- addCommandLineProperties- the flag to set. Default true.
- Returns:
- the current builder
 
- 
setAddConversionServiceFlag to indicate if theApplicationConversionServiceshould be added to the application context'sEnvironment.- Parameters:
- addConversionService- if the conversion service should be added.
- Returns:
- the current builder
- Since:
- 2.1.0
 
- 
addBootstrapRegistryInitializerpublic SpringApplicationBuilder addBootstrapRegistryInitializer(BootstrapRegistryInitializer bootstrapRegistryInitializer) AddsBootstrapRegistryInitializerinstances that can be used to initialize theBootstrapRegistry.- Parameters:
- bootstrapRegistryInitializer- the bootstrap registry initializer to add
- Returns:
- the current builder
- Since:
- 2.4.5
 
- 
lazyInitializationFlag to control whether the application should be initialized lazily.- Parameters:
- lazyInitialization- the flag to set. Defaults to false.
- Returns:
- the current builder
- Since:
- 2.2
 
- 
propertiesDefault properties for the environment in the formkey=valueorkey:value. Multiple calls to this method are cumulative and will not clear any previously set properties.- Parameters:
- defaultProperties- the properties to set.
- Returns:
- the current builder
- See Also:
 
- 
propertiesDefault properties for the environment.Multiple calls to this method are cumulative and will not clear any previously set properties.- Parameters:
- defaultProperties- the properties to set.
- Returns:
- the current builder
- See Also:
 
- 
propertiesDefault properties for the environment. Multiple calls to this method are cumulative and will not clear any previously set properties.- Parameters:
- defaults- the default properties
- Returns:
- the current builder
- See Also:
 
- 
profilesAdd to the active Spring profiles for this app (and its parent and children).- Parameters:
- profiles- the profiles to add.
- Returns:
- the current builder
 
- 
beanNameGeneratorBean name generator for automatically generated bean names in the application context.- Parameters:
- beanNameGenerator- the generator to set.
- Returns:
- the current builder
 
- 
environmentEnvironment for the application context.- Parameters:
- environment- the environment to set.
- Returns:
- the current builder
 
- 
environmentPrefixPrefix that should be applied when obtaining configuration properties from the system environment.- Parameters:
- environmentPrefix- the environment property prefix to set
- Returns:
- the current builder
- Since:
- 2.5.0
 
- 
resourceLoaderResourceLoaderfor the application context. If a custom class loader is needed, this is where it would be added.- Parameters:
- resourceLoader- the resource loader to set.
- Returns:
- the current builder
 
- 
initializersAdd some initializers to the application (applied to theApplicationContextbefore any bean definitions are loaded).- Parameters:
- initializers- some initializers to add
- Returns:
- the current builder
 
- 
listenersAdd some listeners to the application (listening for SpringApplication events as well as regular Spring events once the context is running). Any listeners that are alsoApplicationContextInitializerwill be added to theinitializersautomatically.- Parameters:
- listeners- some listeners to add
- Returns:
- the current builder
 
- 
applicationStartupConfigure theApplicationStartupto be used with theApplicationContextfor collecting startup metrics.- Parameters:
- applicationStartup- the application startup to use
- Returns:
- the current builder
- Since:
- 2.4.0
 
- 
allowCircularReferencesWhether to allow circular references between beans and automatically try to resolve them.- Parameters:
- allowCircularReferences- whether circular references are allowed
- Returns:
- the current builder
- Since:
- 2.6.0
- See Also:
 
 
-