org.springframework.boot

Class SpringApplication

  • java.lang.Object
    • org.springframework.boot.SpringApplication


  • public class SpringApplication
    extends java.lang.Object
    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
    In most circumstances the static run(Class, String[]) method can be called directly from your main method to bootstrap your application:
     @Configuration
     @EnableAutoConfiguration
     public class MyApplication  {
    
       // ... Bean definitions
    
       public static void main(String[] args) {
         SpringApplication.run(MyApplication.class, args);
       }
     }
     

    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)
     }
     
    SpringApplications can read beans from a variety of different sources. It is generally recommended that a single @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
    Configuration properties are also bound to the SpringApplication. This makes it possible to set SpringApplication properties dynamically, like additional sources ("spring.main.sources" - a CSV list) the flag to indicate a web environment ("spring.main.web-application-type=none") or the flag to switch off the banner ("spring.main.banner-mode=off").

    Since:
    1.0.0
    See Also:
    run(Class, String[]), run(Class[], String[]), SpringApplication(Class...)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      void addBootstrapper(Bootstrapper bootstrapper)
      Deprecated. 
      since 2.4.5 for removal in 2.6 in favor of addBootstrapRegistryInitializer(BootstrapRegistryInitializer)
      void addBootstrapRegistryInitializer(BootstrapRegistryInitializer bootstrapRegistryInitializer)
      Adds BootstrapRegistryInitializer instances that can be used to initialize the BootstrapRegistry.
      void addInitializers(org.springframework.context.ApplicationContextInitializer<?>... initializers)
      Add ApplicationContextInitializers to be applied to the Spring ApplicationContext.
      void addListeners(org.springframework.context.ApplicationListener<?>... listeners)
      Add ApplicationListeners to be applied to the SpringApplication and registered with the ApplicationContext.
      void addPrimarySources(java.util.Collection<java.lang.Class<?>> additionalPrimarySources)
      Add additional items to the primary sources that will be added to an ApplicationContext when run(String...) is called.
      protected void afterRefresh(org.springframework.context.ConfigurableApplicationContext context, ApplicationArguments args)
      Called after the context has been refreshed.
      protected void applyInitializers(org.springframework.context.ConfigurableApplicationContext context)
      Apply any ApplicationContextInitializers to the context before it is refreshed.
      protected void bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment)
      Bind the environment to the SpringApplication.
      protected void configureEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String[] args)
      protected void configureProfiles(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String[] args)
      Configure which profiles are active (or active by default) for this application environment.
      protected void configurePropertySources(org.springframework.core.env.ConfigurableEnvironment environment, java.lang.String[] args)
      Add, remove or re-order any PropertySources in this application's environment.
      protected org.springframework.context.ConfigurableApplicationContext createApplicationContext()
      Strategy method used to create the ApplicationContext.
      protected org.springframework.boot.BeanDefinitionLoader createBeanDefinitionLoader(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, java.lang.Object[] sources)
      Factory method used to create the BeanDefinitionLoader.
      static int exit(org.springframework.context.ApplicationContext context, ExitCodeGenerator... exitCodeGenerators)
      Static helper that can be used to exit a SpringApplication and obtain a code indicating success (0) or otherwise.
      java.util.Set<java.lang.String> getAdditionalProfiles()
      Return an immutable set of any additional profiles in use.
      java.util.Set<java.lang.Object> getAllSources()
      Return an immutable set of all the sources that will be added to an ApplicationContext when run(String...) is called.
      protected org.apache.commons.logging.Log getApplicationLog()
      Returns the Log for the application.
      org.springframework.core.metrics.ApplicationStartup getApplicationStartup()
      Returns the ApplicationStartup used for collecting startup metrics.
      java.lang.ClassLoader getClassLoader()
      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.
      java.lang.String getEnvironmentPrefix()
      Return a prefix that should be applied when obtaining configuration properties from the system environment.
      java.util.Set<org.springframework.context.ApplicationContextInitializer<?>> getInitializers()
      Returns read-only ordered Set of the ApplicationContextInitializers that will be applied to the Spring ApplicationContext.
      java.util.Set<org.springframework.context.ApplicationListener<?>> getListeners()
      Returns read-only ordered Set of the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext .
      java.lang.Class<?> getMainApplicationClass()
      Returns the main application class that has been deduced or explicitly configured.
      org.springframework.core.io.ResourceLoader getResourceLoader()
      The ResourceLoader that will be used in the ApplicationContext.
      static SpringApplicationShutdownHandlers getShutdownHandlers()
      Return a SpringApplicationShutdownHandlers instance that can be used to add or remove handlers that perform actions before the JVM is shutdown.
      java.util.Set<java.lang.String> getSources()
      Returns a mutable set of the sources that will be added to an ApplicationContext when run(String...) is called.
      WebApplicationType getWebApplicationType()
      Returns the type of web application that is being run.
      protected void load(org.springframework.context.ApplicationContext context, java.lang.Object[] sources)
      Load beans into the application context.
      protected void logStartupInfo(boolean isRoot)
      Called to log startup information, subclasses may override to add additional logging.
      protected void logStartupProfileInfo(org.springframework.context.ConfigurableApplicationContext context)
      Called to log active profile information.
      static void main(java.lang.String[] args)
      A basic main that can be used to launch an application.
      protected void postProcessApplicationContext(org.springframework.context.ConfigurableApplicationContext context)
      Apply any relevant post processing the ApplicationContext.
      protected void refresh(org.springframework.context.ConfigurableApplicationContext applicationContext)
      Refresh the underlying ApplicationContext.
      protected void registerLoggedException(java.lang.Throwable exception)
      Register that the given exception has been logged.
      static org.springframework.context.ConfigurableApplicationContext run(java.lang.Class<?>[] primarySources, java.lang.String[] args)
      Static helper that can be used to run a SpringApplication from the specified sources using default settings and user supplied arguments.
      static org.springframework.context.ConfigurableApplicationContext run(java.lang.Class<?> primarySource, java.lang.String... args)
      Static helper that can be used to run a SpringApplication from the specified source using default settings.
      org.springframework.context.ConfigurableApplicationContext run(java.lang.String... args)
      Run the Spring application, creating and refreshing a new ApplicationContext.
      void setAddCommandLineProperties(boolean addCommandLineProperties)
      Sets if a CommandLinePropertySource should be added to the application context in order to expose arguments.
      void setAddConversionService(boolean addConversionService)
      Sets if the ApplicationConversionService should be added to the application context's Environment.
      void setAdditionalProfiles(java.lang.String... profiles)
      Set additional profile values to use (on top of those set in system or command line properties).
      void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
      Sets if bean definition overriding, by registering a definition with the same name as an existing definition, should be allowed.
      void setApplicationContextClass(java.lang.Class<? extends org.springframework.context.ConfigurableApplicationContext> applicationContextClass)
      Deprecated. 
      since 2.4.0 for removal in 2.6.0 in favor of setApplicationContextFactory(ApplicationContextFactory)
      void setApplicationContextFactory(ApplicationContextFactory applicationContextFactory)
      Sets the factory that will be called to create the application context.
      void setApplicationStartup(org.springframework.core.metrics.ApplicationStartup applicationStartup)
      Set the ApplicationStartup to use for collecting startup metrics.
      void setBanner(Banner banner)
      Sets the Banner instance which will be used to print the banner when no static banner file is provided.
      void setBannerMode(Banner.Mode bannerMode)
      Sets the mode used to display the banner when the application runs.
      void setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)
      Sets the bean name generator that should be used when generating bean names.
      void setDefaultProperties(java.util.Map<java.lang.String,java.lang.Object> defaultProperties)
      Set default environment properties which will be used in addition to those in the existing Environment.
      void setDefaultProperties(java.util.Properties defaultProperties)
      Convenient alternative to setDefaultProperties(Map).
      void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)
      Sets the underlying environment that should be used with the created application context.
      void setEnvironmentPrefix(java.lang.String environmentPrefix)
      Set the prefix that should be applied when obtaining configuration properties from the system environment.
      void setHeadless(boolean headless)
      Sets if the application is headless and should not instantiate AWT.
      void setInitializers(java.util.Collection<? extends org.springframework.context.ApplicationContextInitializer<?>> initializers)
      Sets the ApplicationContextInitializer that will be applied to the Spring ApplicationContext.
      void setLazyInitialization(boolean lazyInitialization)
      Sets if beans should be initialized lazily.
      void setListeners(java.util.Collection<? extends org.springframework.context.ApplicationListener<?>> listeners)
      Sets the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext.
      void setLogStartupInfo(boolean logStartupInfo)
      Sets if the application information should be logged when the application starts.
      void setMainApplicationClass(java.lang.Class<?> mainApplicationClass)
      Set a specific main application class that will be used as a log source and to obtain version information.
      void setRegisterShutdownHook(boolean registerShutdownHook)
      Sets if the created ApplicationContext should have a shutdown hook registered.
      void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
      Sets the ResourceLoader that should be used when loading resources.
      void setSources(java.util.Set<java.lang.String> sources)
      Set additional sources that will be used to create an ApplicationContext.
      void setWebApplicationType(WebApplicationType webApplicationType)
      Sets the type of web application to be run.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_CONTEXT_CLASS

        @Deprecated
        public static final java.lang.String DEFAULT_CONTEXT_CLASS
        Deprecated. since 2.4.0 for removal in 2.6.0 in favor of using a ApplicationContextFactory
        The class name of application context that will be used by default for non-web environments.
        See Also:
        Constant Field Values
      • DEFAULT_SERVLET_WEB_CONTEXT_CLASS

        @Deprecated
        public static final java.lang.String DEFAULT_SERVLET_WEB_CONTEXT_CLASS
        Deprecated. since 2.4.0 for removal in 2.6.0 in favor of using an ApplicationContextFactory
        The class name of application context that will be used by default for web environments.
        See Also:
        Constant Field Values
      • DEFAULT_REACTIVE_WEB_CONTEXT_CLASS

        @Deprecated
        public static final java.lang.String DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
        Deprecated. since 2.4.0 for removal in 2.6.0 in favor of using an ApplicationContextFactory
        The class name of application context that will be used by default for reactive web environments.
        See Also:
        Constant Field Values
      • BANNER_LOCATION_PROPERTY_VALUE

        public static final java.lang.String BANNER_LOCATION_PROPERTY_VALUE
        Default banner location.
        See Also:
        Constant Field Values
      • BANNER_LOCATION_PROPERTY

        public static final java.lang.String BANNER_LOCATION_PROPERTY
        Banner location property key.
        See Also:
        Constant Field Values
    • Method Detail

      • run

        public org.springframework.context.ConfigurableApplicationContext run(java.lang.String... args)
        Run the Spring application, creating and refreshing a new ApplicationContext.
        Parameters:
        args - the application arguments (usually passed from a Java main method)
        Returns:
        a running ApplicationContext
      • configurePropertySources

        protected void configurePropertySources(org.springframework.core.env.ConfigurableEnvironment environment,
                                                java.lang.String[] args)
        Add, remove or re-order any PropertySources in this application's environment.
        Parameters:
        environment - this application's environment
        args - arguments passed to the run method
        See Also:
        configureEnvironment(ConfigurableEnvironment, String[])
      • configureProfiles

        protected void configureProfiles(org.springframework.core.env.ConfigurableEnvironment environment,
                                         java.lang.String[] args)
        Configure which profiles are active (or active by default) for this application environment. Additional profiles may be activated during configuration file processing via the spring.profiles.active property.
        Parameters:
        environment - this application's environment
        args - arguments passed to the run method
        See Also:
        configureEnvironment(ConfigurableEnvironment, String[]), ConfigFileApplicationListener
      • bindToSpringApplication

        protected void bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment)
        Bind the environment to the SpringApplication.
        Parameters:
        environment - the environment to bind
      • createApplicationContext

        protected org.springframework.context.ConfigurableApplicationContext createApplicationContext()
        Strategy method used to create the ApplicationContext. By default this method will respect any explicitly set application context class or factory before falling back to a suitable default.
        Returns:
        the application context (not yet refreshed)
        See Also:
        setApplicationContextClass(Class), setApplicationContextFactory(ApplicationContextFactory)
      • postProcessApplicationContext

        protected void postProcessApplicationContext(org.springframework.context.ConfigurableApplicationContext context)
        Apply any relevant post processing the ApplicationContext. Subclasses can apply additional processing as required.
        Parameters:
        context - the application context
      • applyInitializers

        protected void applyInitializers(org.springframework.context.ConfigurableApplicationContext context)
        Apply any ApplicationContextInitializers to the context before it is refreshed.
        Parameters:
        context - the configured ApplicationContext (not refreshed yet)
        See Also:
        ConfigurableApplicationContext.refresh()
      • logStartupInfo

        protected void logStartupInfo(boolean isRoot)
        Called to log startup information, subclasses may override to add additional logging.
        Parameters:
        isRoot - true if this application is the root of a context hierarchy
      • logStartupProfileInfo

        protected void logStartupProfileInfo(org.springframework.context.ConfigurableApplicationContext context)
        Called to log active profile information.
        Parameters:
        context - the application context
      • getApplicationLog

        protected org.apache.commons.logging.Log getApplicationLog()
        Returns the Log for the application. By default will be deduced.
        Returns:
        the application log
      • load

        protected void load(org.springframework.context.ApplicationContext context,
                            java.lang.Object[] sources)
        Load beans into the application context.
        Parameters:
        context - the context to load beans into
        sources - the sources to load
      • getResourceLoader

        public org.springframework.core.io.ResourceLoader getResourceLoader()
        The ResourceLoader that will be used in the ApplicationContext.
        Returns:
        the resourceLoader the resource loader that will be used in the ApplicationContext (or null if the default)
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        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.
        Returns:
        a ClassLoader (never null)
      • createBeanDefinitionLoader

        protected org.springframework.boot.BeanDefinitionLoader createBeanDefinitionLoader(org.springframework.beans.factory.support.BeanDefinitionRegistry registry,
                                                                                           java.lang.Object[] sources)
        Factory method used to create the BeanDefinitionLoader.
        Parameters:
        registry - the bean definition registry
        sources - the sources to load
        Returns:
        the BeanDefinitionLoader that will be used to load beans
      • refresh

        protected void refresh(org.springframework.context.ConfigurableApplicationContext applicationContext)
        Refresh the underlying ApplicationContext.
        Parameters:
        applicationContext - the application context to refresh
      • afterRefresh

        protected void afterRefresh(org.springframework.context.ConfigurableApplicationContext context,
                                    ApplicationArguments args)
        Called after the context has been refreshed.
        Parameters:
        context - the application context
        args - the application arguments
      • registerLoggedException

        protected void registerLoggedException(java.lang.Throwable exception)
        Register that the given exception has been logged. By default, if the running in the main thread, this method will suppress additional printing of the stacktrace.
        Parameters:
        exception - the exception that was logged
      • getMainApplicationClass

        public java.lang.Class<?> getMainApplicationClass()
        Returns the main application class that has been deduced or explicitly configured.
        Returns:
        the main application class or null
      • setMainApplicationClass

        public void setMainApplicationClass(java.lang.Class<?> mainApplicationClass)
        Set a specific main application class that will be used as a log source and to obtain version information. By default the main application class will be deduced. Can be set to null if there is no explicit application class.
        Parameters:
        mainApplicationClass - the mainApplicationClass to set or null
      • getWebApplicationType

        public WebApplicationType getWebApplicationType()
        Returns the type of web application that is being run.
        Returns:
        the type of web application
        Since:
        2.0.0
      • setWebApplicationType

        public void setWebApplicationType(WebApplicationType webApplicationType)
        Sets the type of web application to be run. If not explicitly set the type of web application will be deduced based on the classpath.
        Parameters:
        webApplicationType - the web application type
        Since:
        2.0.0
      • setAllowBeanDefinitionOverriding

        public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
        Sets if bean definition overriding, by registering a definition with the same name as an existing definition, should be allowed. Defaults to false.
        Parameters:
        allowBeanDefinitionOverriding - if overriding is allowed
        Since:
        2.1.0
        See Also:
        DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
      • setLazyInitialization

        public void setLazyInitialization(boolean lazyInitialization)
        Sets if beans should be initialized lazily. Defaults to false.
        Parameters:
        lazyInitialization - if initialization should be lazy
        Since:
        2.2
        See Also:
        BeanDefinition.setLazyInit(boolean)
      • setHeadless

        public void setHeadless(boolean headless)
        Sets if the application is headless and should not instantiate AWT. Defaults to true to prevent java icons appearing.
        Parameters:
        headless - if the application is headless
      • setRegisterShutdownHook

        public void setRegisterShutdownHook(boolean registerShutdownHook)
        Sets if the created ApplicationContext should have a shutdown hook registered. Defaults to true to ensure that JVM shutdowns are handled gracefully.
        Parameters:
        registerShutdownHook - if the shutdown hook should be registered
        See Also:
        getShutdownHandlers()
      • setBanner

        public void setBanner(Banner banner)
        Sets the Banner instance which will be used to print the banner when no static banner file is provided.
        Parameters:
        banner - the Banner instance to use
      • setBannerMode

        public void setBannerMode(Banner.Mode bannerMode)
        Sets the mode used to display the banner when the application runs. Defaults to Banner.Mode.CONSOLE.
        Parameters:
        bannerMode - the mode used to display the banner
      • setLogStartupInfo

        public void setLogStartupInfo(boolean logStartupInfo)
        Sets if the application information should be logged when the application starts. Defaults to true.
        Parameters:
        logStartupInfo - if startup info should be logged.
      • setAddCommandLineProperties

        public void setAddCommandLineProperties(boolean addCommandLineProperties)
        Sets if a CommandLinePropertySource should be added to the application context in order to expose arguments. Defaults to true.
        Parameters:
        addCommandLineProperties - if command line arguments should be exposed
      • setAddConversionService

        public void setAddConversionService(boolean addConversionService)
        Sets if the ApplicationConversionService should be added to the application context's Environment.
        Parameters:
        addConversionService - if the application conversion service should be added
        Since:
        2.1.0
      • setDefaultProperties

        public void setDefaultProperties(java.util.Map<java.lang.String,java.lang.Object> defaultProperties)
        Set default environment properties which will be used in addition to those in the existing Environment.
        Parameters:
        defaultProperties - the additional properties to set
      • setDefaultProperties

        public void setDefaultProperties(java.util.Properties defaultProperties)
        Convenient alternative to setDefaultProperties(Map).
        Parameters:
        defaultProperties - some Properties
      • setAdditionalProfiles

        public void setAdditionalProfiles(java.lang.String... profiles)
        Set additional profile values to use (on top of those set in system or command line properties).
        Parameters:
        profiles - the additional profiles to set
      • getAdditionalProfiles

        public java.util.Set<java.lang.String> getAdditionalProfiles()
        Return an immutable set of any additional profiles in use.
        Returns:
        the additional profiles
      • setBeanNameGenerator

        public void setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)
        Sets the bean name generator that should be used when generating bean names.
        Parameters:
        beanNameGenerator - the bean name generator
      • setEnvironment

        public void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)
        Sets the underlying environment that should be used with the created application context.
        Parameters:
        environment - the environment
      • addPrimarySources

        public void addPrimarySources(java.util.Collection<java.lang.Class<?>> additionalPrimarySources)
        Add additional items to the primary sources that will be added to an ApplicationContext when run(String...) is called.

        The sources here are added to those that were set in the constructor. Most users should consider using getSources()/setSources(Set) rather than calling this method.

        Parameters:
        additionalPrimarySources - the additional primary sources to add
        See Also:
        SpringApplication(Class...), getSources(), setSources(Set), getAllSources()
      • getSources

        public java.util.Set<java.lang.String> getSources()
        Returns a mutable set of the sources that will be added to an ApplicationContext when run(String...) is called.

        Sources set here will be used in addition to any primary sources set in the constructor.

        Returns:
        the application sources.
        See Also:
        SpringApplication(Class...), getAllSources()
      • setSources

        public void setSources(java.util.Set<java.lang.String> sources)
        Set additional sources that will be used to create an ApplicationContext. A source can be: a class name, package name, or an XML resource location.

        Sources set here will be used in addition to any primary sources set in the constructor.

        Parameters:
        sources - the application sources to set
        See Also:
        SpringApplication(Class...), getAllSources()
      • getAllSources

        public java.util.Set<java.lang.Object> getAllSources()
        Return an immutable set of all the sources that will be added to an ApplicationContext when run(String...) is called. This method combines any primary sources specified in the constructor with any additional ones that have been explicitly set.
        Returns:
        an immutable set of all sources
      • setResourceLoader

        public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
        Sets the ResourceLoader that should be used when loading resources.
        Parameters:
        resourceLoader - the resource loader
      • getEnvironmentPrefix

        public java.lang.String getEnvironmentPrefix()
        Return a prefix that should be applied when obtaining configuration properties from the system environment.
        Returns:
        the environment property prefix
        Since:
        2.5.0
      • setEnvironmentPrefix

        public void setEnvironmentPrefix(java.lang.String environmentPrefix)
        Set the prefix that should be applied when obtaining configuration properties from the system environment.
        Parameters:
        environmentPrefix - the environment property prefix to set
        Since:
        2.5.0
      • setApplicationContextClass

        @Deprecated
        public void setApplicationContextClass(java.lang.Class<? extends org.springframework.context.ConfigurableApplicationContext> applicationContextClass)
        Deprecated. since 2.4.0 for removal in 2.6.0 in favor of setApplicationContextFactory(ApplicationContextFactory)
        Sets the type of Spring ApplicationContext that will be created. If not specified defaults to DEFAULT_SERVLET_WEB_CONTEXT_CLASS for web based applications or AnnotationConfigApplicationContext for non web based applications.
        Parameters:
        applicationContextClass - the context class to set
      • setInitializers

        public void setInitializers(java.util.Collection<? extends org.springframework.context.ApplicationContextInitializer<?>> initializers)
        Sets the ApplicationContextInitializer that will be applied to the Spring ApplicationContext.
        Parameters:
        initializers - the initializers to set
      • addInitializers

        public void addInitializers(org.springframework.context.ApplicationContextInitializer<?>... initializers)
        Add ApplicationContextInitializers to be applied to the Spring ApplicationContext.
        Parameters:
        initializers - the initializers to add
      • getInitializers

        public java.util.Set<org.springframework.context.ApplicationContextInitializer<?>> getInitializers()
        Returns read-only ordered Set of the ApplicationContextInitializers that will be applied to the Spring ApplicationContext.
        Returns:
        the initializers
      • setListeners

        public void setListeners(java.util.Collection<? extends org.springframework.context.ApplicationListener<?>> listeners)
        Sets the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext.
        Parameters:
        listeners - the listeners to set
      • addListeners

        public void addListeners(org.springframework.context.ApplicationListener<?>... listeners)
        Add ApplicationListeners to be applied to the SpringApplication and registered with the ApplicationContext.
        Parameters:
        listeners - the listeners to add
      • getListeners

        public java.util.Set<org.springframework.context.ApplicationListener<?>> getListeners()
        Returns read-only ordered Set of the ApplicationListeners that will be applied to the SpringApplication and registered with the ApplicationContext .
        Returns:
        the listeners
      • setApplicationStartup

        public void setApplicationStartup(org.springframework.core.metrics.ApplicationStartup applicationStartup)
        Set the ApplicationStartup to use for collecting startup metrics.
        Parameters:
        applicationStartup - the application startup to use
        Since:
        2.4.0
      • getApplicationStartup

        public org.springframework.core.metrics.ApplicationStartup getApplicationStartup()
        Returns the ApplicationStartup used for collecting startup metrics.
        Returns:
        the application startup
        Since:
        2.4.0
      • run

        public static org.springframework.context.ConfigurableApplicationContext run(java.lang.Class<?> primarySource,
                                                                                     java.lang.String... args)
        Static helper that can be used to run a SpringApplication from the specified source using default settings.
        Parameters:
        primarySource - the primary source to load
        args - the application arguments (usually passed from a Java main method)
        Returns:
        the running ApplicationContext
      • run

        public static org.springframework.context.ConfigurableApplicationContext run(java.lang.Class<?>[] primarySources,
                                                                                     java.lang.String[] args)
        Static helper that can be used to run a SpringApplication from the specified sources using default settings and user supplied arguments.
        Parameters:
        primarySources - the primary sources to load
        args - the application arguments (usually passed from a Java main method)
        Returns:
        the running ApplicationContext
      • main

        public static void main(java.lang.String[] args)
                         throws java.lang.Exception
        A basic main that can be used to launch an application. This method is useful when application sources are defined via a --spring.main.sources command line argument.

        Most developers will want to define their own main method and call the run method instead.

        Parameters:
        args - command line arguments
        Throws:
        java.lang.Exception - if the application cannot be started
        See Also:
        run(Class[], String[]), run(Class, String...)
      • exit

        public static int exit(org.springframework.context.ApplicationContext context,
                               ExitCodeGenerator... exitCodeGenerators)
        Static helper that can be used to exit a SpringApplication and obtain a code indicating success (0) or otherwise. Does not throw exceptions but should print stack traces of any encountered. Applies the specified ExitCodeGenerator in addition to any Spring beans that implement ExitCodeGenerator. In the case of multiple exit codes the highest value will be used (or if all values are negative, the lowest value will be used)
        Parameters:
        context - the context to close if possible
        exitCodeGenerators - exit code generators
        Returns:
        the outcome (0 if successful)