public class SpringApplicationBuilder extends Object
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 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.
Constructor and Description |
---|
SpringApplicationBuilder(Object... sources) |
Modifier and Type | Method and Description |
---|---|
SpringApplicationBuilder |
addCommandLineProperties(boolean addCommandLineProperties)
Flag to indicate that command line arguments should be added to the environment.
|
SpringApplication |
application()
Accessor for the current application.
|
SpringApplicationBuilder |
beanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)
Bean name generator for automatically generated bean names in the application
context.
|
SpringApplicationBuilder |
child(Object... sources)
Create a child application with the provided sources.
|
org.springframework.context.ConfigurableApplicationContext |
context()
Accessor for the current application context.
|
SpringApplicationBuilder |
contextClass(Class<? extends org.springframework.context.ConfigurableApplicationContext> cls)
Explicitly set the context class to be used.
|
SpringApplicationBuilder |
defaultArgs(String... defaultArgs)
Default command line arguments (overridden by explicit arguments at runtime in
run(String...) ). |
SpringApplicationBuilder |
environment(org.springframework.core.env.ConfigurableEnvironment environment)
Environment for the application context.
|
SpringApplicationBuilder |
initializers(org.springframework.context.ApplicationContextInitializer<?>... initializers)
Add some initializers to the application (applied to the
ApplicationContext
before any bean definitions are loaded). |
SpringApplicationBuilder |
logStartupInfo(boolean logStartupInfo)
Flag to indicate the startup information should be logged.
|
SpringApplicationBuilder |
main(Class<?> mainApplicationClass)
Fixes the main application class that is used to anchor the startup messages.
|
SpringApplicationBuilder |
parent(org.springframework.context.ConfigurableApplicationContext parent)
Add an already running parent context to an existing application.
|
SpringApplicationBuilder |
parent(Object... sources)
Add a parent application with the provided sources.
|
SpringApplicationBuilder |
profiles(String... profiles)
Set the active Spring profiles for this app (and its parent and children).
|
SpringApplicationBuilder |
resourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
ResourceLoader for the application context. |
org.springframework.context.ConfigurableApplicationContext |
run(String... args)
Create an application context (and its parent if specified) with the command line
args provided.
|
SpringApplicationBuilder |
showBanner(boolean showBanner)
Flag to indicate the startup banner should be printed.
|
SpringApplicationBuilder |
sibling(Object... sources)
Create a sibling application (one with the same parent).
|
SpringApplicationBuilder |
sibling(Object[] sources,
String... args)
Create a sibling application (one with the same parent).
|
SpringApplicationBuilder |
sources(Class<?>... sources)
Add more sources (configuration classes and components) to this application
|
SpringApplicationBuilder |
sources(Object... sources)
Add more sources to use in this application.
|
SpringApplicationBuilder |
web(boolean webEnvironment)
Flag to explicitly request a web or non-web environment (auto detected based on
classpath if not set).
|
public SpringApplicationBuilder(Object... sources)
public org.springframework.context.ConfigurableApplicationContext context()
public SpringApplication application()
public org.springframework.context.ConfigurableApplicationContext run(String... args)
args
- the command line argumentspublic SpringApplicationBuilder child(Object... sources)
sources
- the sources for the application (Spring configuration)public SpringApplicationBuilder parent(Object... sources)
sources
- the sources for the application (Spring configuration)public SpringApplicationBuilder parent(org.springframework.context.ConfigurableApplicationContext parent)
parent
- the parent contextpublic SpringApplicationBuilder sibling(Object... sources)
sources
- the sources for the application (Spring configuration)public SpringApplicationBuilder sibling(Object[] sources, String... args)
sources
- the sources for the application (Spring configuration)args
- the command line arguments to use when starting the current app and its
parentpublic SpringApplicationBuilder contextClass(Class<? extends org.springframework.context.ConfigurableApplicationContext> cls)
cls
- the context class to usepublic SpringApplicationBuilder sources(Object... sources)
sources
- the sources to addpublic SpringApplicationBuilder sources(Class<?>... sources)
sources
- the sources to addpublic SpringApplicationBuilder web(boolean webEnvironment)
webEnvironment
- the flag to setpublic SpringApplicationBuilder logStartupInfo(boolean logStartupInfo)
logStartupInfo
- the flag to set. Default true.public SpringApplicationBuilder showBanner(boolean showBanner)
showBanner
- the flag to set. Default true.public SpringApplicationBuilder main(Class<?> mainApplicationClass)
mainApplicationClass
- the class to use.public SpringApplicationBuilder addCommandLineProperties(boolean addCommandLineProperties)
addCommandLineProperties
- the flag to set. Default true.public SpringApplicationBuilder defaultArgs(String... defaultArgs)
run(String...)
).defaultArgs
- the args to set.public SpringApplicationBuilder profiles(String... profiles)
defaultArgs("--spring.profiles.active=[profiles]")
profiles
- the profiles to set.public SpringApplicationBuilder beanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)
beanNameGenerator
- the generator to set.public SpringApplicationBuilder environment(org.springframework.core.env.ConfigurableEnvironment environment)
environment
- the environment to set.public SpringApplicationBuilder resourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
ResourceLoader
for the application context. If a custom class loader is
needed, this is where it would be added.resourceLoader
- the resource loader to set.public SpringApplicationBuilder initializers(org.springframework.context.ApplicationContextInitializer<?>... initializers)
ApplicationContext
before any bean definitions are loaded).initializers
- some initializers to addCopyright © 2013. All rights reserved.