SpringApplication
Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:
- Create an appropriate ApplicationContext instance (depending on your classpath)
- Register a CommandLinePropertySource to expose command line arguments as Spring properties
- Refresh the application context, loading all singleton beans
- Trigger any CommandLineRunner beans
@Configuration
@EnableAutoConfiguration
public class MyApplication {
// ... Bean definitions
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Content copied to clipboard
For more advanced configuration a SpringApplication instance can be created and customized before being run:
public static void main(String[] args) {
SpringApplication application = new SpringApplication(MyApplication.class);
// ... customize application settings here
application.run(args)
}
Content copied to clipboard
@Configuration
class is used to bootstrap your application, however, you may also set sources from: - The fully qualified class name to be loaded by AnnotatedBeanDefinitionReader
- The location of an XML resource to be loaded by XmlBeanDefinitionReader, or a groovy script to be loaded by GroovyBeanDefinitionReader
- The name of a package to be scanned by ClassPathBeanDefinitionScanner
Author
Phillip Webb
Dave Syer
Andy Wilkinson
Christian Dupuis
Stephane Nicoll
Jeremy Rickard
Craig Burke
Michael Simons
Madhura Bhave
Brian Clozel
Ethan Rubinson
Chris Bono
Moritz Halbritter
Tadaya Tsuyukubo
Lasse Wulff
Yanming Zhou
Since
1.0.0
See also
Constructors
Link copied to clipboard
Create a new SpringApplication instance.
Create a new SpringApplication instance.
Types
Link copied to clipboard
Exception that can be thrown to silently exit a running SpringApplication without handling run failures.
Link copied to clipboard
Used to configure and run an augmented SpringApplication where additional configuration should be applied.
Link copied to clipboard
interface Running
Provides access to details of a SpringApplication run using run.
Properties
Functions
Link copied to clipboard
open fun addBootstrapRegistryInitializer(bootstrapRegistryInitializer: BootstrapRegistryInitializer)
Adds BootstrapRegistryInitializer instances that can be used to initialize the BootstrapRegistry.
Link copied to clipboard
Add ApplicationContextInitializers to be applied to the Spring ApplicationContext.
Link copied to clipboard
Add ApplicationListeners to be applied to the SpringApplication and registered with the ApplicationContext.
Link copied to clipboard
Add additional items to the primary sources that will be added to an ApplicationContext when run is called.
Link copied to clipboard
Static helper that can be used to exit a SpringApplication and obtain a code indicating success (0) or otherwise.
Link copied to clipboard
Create an application from an existing
main
method that can run with additional @Configuration
or bean classes.Link copied to clipboard
Return an immutable set of all the sources that will be added to an ApplicationContext when run is called.
Link copied to clipboard
Either the ClassLoader that will be used in the ApplicationContext (if resourceLoader is set), or the context class loader (if not null), or the loader of the Spring ClassUtils class.
Link copied to clipboard
Returns read-only ordered Set of the ApplicationContextInitializers that will be applied to the Spring ApplicationContext.
Link copied to clipboard
Returns read-only ordered Set of the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext .
Link copied to clipboard
Return a SpringApplicationShutdownHandlers instance that can be used to add or remove handlers that perform actions before the JVM is shutdown.
Link copied to clipboard
Returns a mutable set of the sources that will be added to an ApplicationContext when run is called.
Link copied to clipboard
Returns the type of web application that is being run.
Link copied to clipboard
Whether to keep the application alive even if there are no more non-daemon threads.
Link copied to clipboard
Run the Spring application, creating and refreshing a new ApplicationContext.
Static helper that can be used to run a SpringApplication from the specified source using default settings.
open fun run(primarySources: Array<Class<out Any>>, args: Array<String>): ConfigurableApplicationContext
Static helper that can be used to run a SpringApplication from the specified sources using default settings and user supplied arguments.
Link copied to clipboard
Sets if a CommandLinePropertySource should be added to the application context in order to expose arguments.
Link copied to clipboard
Sets if the ApplicationConversionService should be added to the application context's Environment.
Link copied to clipboard
Set additional profile values to use (on top of those set in system or command line properties).
Link copied to clipboard
Sets if bean definition overriding, by registering a definition with the same name as an existing definition, should be allowed.
Link copied to clipboard
Sets whether to allow circular references between beans and automatically try to resolve them.
Link copied to clipboard
Sets the factory that will be called to create the application context.
Link copied to clipboard
Sets the mode used to display the banner when the application runs.
Link copied to clipboard
Sets the bean name generator that should be used when generating bean names.
Link copied to clipboard
Set default environment properties which will be used in addition to those in the existing Environment.
Convenient alternative to setDefaultProperties.
Link copied to clipboard
Sets the underlying environment that should be used with the created application context.
Link copied to clipboard
Sets if the application is headless and should not instantiate AWT.
Link copied to clipboard
Sets the ApplicationContextInitializer that will be applied to the Spring ApplicationContext.
Link copied to clipboard
Set whether to keep the application alive even if there are no more non-daemon threads.
Link copied to clipboard
Sets if beans should be initialized lazily.
Link copied to clipboard
Sets the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext.
Link copied to clipboard
Sets if the application information should be logged when the application starts.
Link copied to clipboard
Sets if the created ApplicationContext should have a shutdown hook registered.
Link copied to clipboard
Set additional sources that will be used to create an ApplicationContext.
Link copied to clipboard
Sets the type of web application to be run.
Link copied to clipboard
Perform the given action with the given SpringApplicationHook attached if the action triggers an application run.