Interface ApplicationContextBuilder

All Known Implementing Classes:
DefaultApplicationContextBuilder, Micronaut

public interface ApplicationContextBuilder
An interface for building an application context.
Since:
1.0
Author:
graemerocher
  • Method Details

    • eagerInitConfiguration

      @NonNull default ApplicationContextBuilder eagerInitConfiguration(boolean eagerInitConfiguration)
      Whether to eager initialize ConfigurationProperties beans.
      Parameters:
      eagerInitConfiguration - True if configuration properties should be eagerly initialized
      Returns:
      The context builder
      Since:
      2.0
    • eagerInitSingletons

      @NonNull default ApplicationContextBuilder eagerInitSingletons(boolean eagerInitSingletons)
      Whether to eager initialize singleton beans.
      Parameters:
      eagerInitSingletons - True if singletons should be eagerly initialized
      Returns:
      The context builder
      Since:
      2.0
    • enableDefaultPropertySources

      @NonNull default ApplicationContextBuilder enableDefaultPropertySources(boolean areEnabled)
      Specify whether the default set of property sources should be enabled (default is true).
      Parameters:
      areEnabled - Whether the default property sources are enabled
      Returns:
      This builder
      Since:
      3.7.0
    • eagerInitAnnotated

      @NonNull ApplicationContextBuilder eagerInitAnnotated(Class<? extends Annotation>... annotations)
      Specifies to eager init the given annotated types.
      Parameters:
      annotations - The annotation stereotypes
      Returns:
      The context builder
      Since:
      2.0
    • overrideConfigLocations

      @NonNull ApplicationContextBuilder overrideConfigLocations(String... configLocations)
      Override default config locations.
      Parameters:
      configLocations - The config locations
      Returns:
      This environment
      Since:
      2.0
    • singletons

      Additional singletons to register prior to startup.
      Parameters:
      beans - The beans
      Returns:
      This builder
    • deduceEnvironment

      @NonNull ApplicationContextBuilder deduceEnvironment(@Nullable Boolean deduceEnvironment)
      If set to true (the default is true) Micronaut will attempt to automatically deduce the environment it is running in using environment variables and/or stack trace inspection.

      This method differs from deduceCloudEnvironment(boolean) which performs extended network and/or disk probes to try and automatically establish the Cloud environment.

      This behaviour controls the automatic activation of, for example, the Environment.TEST when running tests.

      Parameters:
      deduceEnvironment - The boolean
      Returns:
      This builder
    • deduceCloudEnvironment

      @NonNull ApplicationContextBuilder deduceCloudEnvironment(boolean deduceEnvironment)
      If set to true (the default value is false) Micronaut will attempt to automatically deduce the Cloud environment it is running within.

      Enabling this should be done with caution since network probes are required to figure out whether the application is running in certain clouds like GCP.

      Parameters:
      deduceEnvironment - The boolean
      Returns:
      This builder
      Since:
      4.0.0
    • environments

      @NonNull ApplicationContextBuilder environments(@Nullable String... environments)
      The environments to use.
      Parameters:
      environments - The environments
      Returns:
      This builder
    • defaultEnvironments

      @NonNull ApplicationContextBuilder defaultEnvironments(@Nullable String... environments)
      The environments to use if no other environments are specified.
      Parameters:
      environments - The environments
      Returns:
      This builder
    • packages

      The packages to include for package scanning.
      Parameters:
      packages - The packages
      Returns:
      This builder
    • properties

      Properties to override from the environment.
      Parameters:
      properties - The properties
      Returns:
      This builder
    • propertySources

      @NonNull ApplicationContextBuilder propertySources(@Nullable PropertySource... propertySources)
      Additional property sources.
      Parameters:
      propertySources - The property sources to include
      Returns:
      This builder
    • environmentPropertySource

      @NonNull ApplicationContextBuilder environmentPropertySource(boolean environmentPropertySource)
      Set whether environment variables should contribute to configuration.
      Parameters:
      environmentPropertySource - The boolean
      Returns:
      This builder
    • environmentVariableIncludes

      @NonNull ApplicationContextBuilder environmentVariableIncludes(@Nullable String... environmentVariables)
      Which environment variables should contribute to configuration.
      Parameters:
      environmentVariables - The environment variables
      Returns:
      This builder
    • environmentVariableExcludes

      @NonNull ApplicationContextBuilder environmentVariableExcludes(@Nullable String... environmentVariables)
      Which environment variables should not contribute to configuration.
      Parameters:
      environmentVariables - The environment variables
      Returns:
      This builder
    • mainClass

      The main class used by this application.
      Parameters:
      mainClass - The main class
      Returns:
      This builder
    • classLoader

      The class loader to be used.
      Parameters:
      classLoader - The classloader
      Returns:
      This builder
    • build

      Builds the ApplicationContext, but does not start it.
      Returns:
      The built, but not running ApplicationContext
    • include

      @NonNull ApplicationContextBuilder include(@Nullable String... configurations)
      Allow customizing the configurations that will be loaded.
      Parameters:
      configurations - The configurations to include
      Returns:
      This application
    • exclude

      @NonNull ApplicationContextBuilder exclude(@Nullable String... configurations)
      Allow customizing the configurations that will be loaded.
      Parameters:
      configurations - The configurations to exclude
      Returns:
      This application
    • banner

      @NonNull ApplicationContextBuilder banner(boolean isEnabled)
      Whether the banner is enabled or not.
      Parameters:
      isEnabled - Whether the banner is enabled or not
      Returns:
      This application
    • allowEmptyProviders

      @NonNull ApplicationContextBuilder allowEmptyProviders(boolean shouldAllow)
      Whether to error on an empty bean provider. Defaults to false.
      Parameters:
      shouldAllow - True if empty Provider instances are allowed
      Returns:
      This application
      Since:
      3.0.0
    • args

      Set the command line arguments.
      Parameters:
      args - The arguments
      Returns:
      This application
    • bootstrapEnvironment

      @NonNull default ApplicationContextBuilder bootstrapEnvironment(boolean bootstrapEnv)
      Sets whether the bootstrap environment should be initialized.
      Parameters:
      bootstrapEnv - True if it should be initialized. Default true
      Returns:
      This application
      Since:
      3.1.0
    • start

      @NonNull default ApplicationContext start()
      Starts the ApplicationContext.
      Returns:
      The running ApplicationContext
    • run

      @NonNull default <T extends AutoCloseable> T run(@NonNull Class<T> type)
      Run the ApplicationContext with the given type. Returning an instance of the type.
      Type Parameters:
      T - The type, a subclass of AutoCloseable. The close method of the implementation should shutdown the context.
      Parameters:
      type - The type of the bean to run
      Returns:
      The running bean