Class DefaultApplicationContextBuilder
- All Implemented Interfaces:
ApplicationContextBuilder
,ApplicationContextConfiguration
,BeanContextConfiguration
- Direct Known Subclasses:
Micronaut
ApplicationContextBuilder
.- Since:
- 1.0
- Author:
- graemerocher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionallowEmptyProviders
(boolean shouldAllow) Whether to error on an empty bean provider.Set the command line arguments.banner
(boolean isEnabled) Whether the banner is enabled or not.bootstrapEnvironment
(boolean bootstrapEnv) Sets whether the bootstrap environment should be initialized.build()
Builds theApplicationContext
, but does not start it.classLoader
(ClassLoader classLoader) The class loader to be used.deduceCloudEnvironment
(boolean deduceEnvironment) If set totrue
(the default value isfalse
) Micronaut will attempt to automatically deduce the Cloud environment it is running within.deduceEnvironment
(@Nullable Boolean deduceEnvironments) If set totrue
(the default istrue
) Micronaut will attempt to automatically deduce the environment it is running in using environment variables and/or stack trace inspection.defaultEnvironments
(@Nullable String... environments) The environments to use if no other environments are specified.eagerInitAnnotated
(Class<? extends Annotation>... annotations) Specifies to eager init the given annotated types.enableDefaultPropertySources
(boolean areEnabled) Specify whether the default set of property sources should be enabled (default istrue
).environmentPropertySource
(boolean environmentPropertySource) Set whether environment variables should contribute to configuration.environments
(@Nullable String... environments) The environments to use.environmentVariableExcludes
(@Nullable String... environmentVariables) Which environment variables should not contribute to configuration.environmentVariableIncludes
(@Nullable String... environmentVariables) Which environment variables should contribute to configuration.Allow customizing the configurations that will be loaded.The class loader to use.If set totrue
(the default istrue
) Micronaut will attempt to automatically deduce the environment it is running in using environment variables and/or stack trace inspection.Set<Class<? extends Annotation>>
The config locations.The class path resource loader to use.Allow customizing the configurations that will be loaded.boolean
boolean
The banner is enabled by default.boolean
If set totrue
Micronaut will attempt to deduce the environment using safe methods like environment variables and the stack trace.boolean
Whether to load the default set of property sources.boolean
The main class used by this application.protected @NonNull ApplicationContext
Creates theApplicationContext
instance.overrideConfigLocations
(String... configLocations) Override default config locations.The packages to include for package scanning.properties
(@Nullable Map<String, Object> properties) Properties to override from the environment.propertySources
(@Nullable PropertySource... propertySources) Additional property sources.singletons
(Object... beans) Additional singletons to register prior to startup.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.context.ApplicationContextBuilder
eagerInitConfiguration, eagerInitSingletons, run, start
Methods inherited from interface io.micronaut.context.ApplicationContextConfiguration
getConversionService
Methods inherited from interface io.micronaut.context.BeanContextConfiguration
isEagerInitConfiguration, isEagerInitSingletons
-
Constructor Details
-
DefaultApplicationContextBuilder
protected DefaultApplicationContextBuilder()Default constructor.
-
-
Method Details
-
isAllowEmptyProviders
public boolean isAllowEmptyProviders()- Specified by:
isAllowEmptyProviders
in interfaceBeanContextConfiguration
- Returns:
- If a
NoSuchBeanException
should be thrown on a missingBeanProvider
orProvider
-
enableDefaultPropertySources
Description copied from interface:ApplicationContextBuilder
Specify whether the default set of property sources should be enabled (default istrue
).- Specified by:
enableDefaultPropertySources
in interfaceApplicationContextBuilder
- Parameters:
areEnabled
- Whether the default property sources are enabled- Returns:
- This builder
-
isEnableDefaultPropertySources
public boolean isEnableDefaultPropertySources()Description copied from interface:ApplicationContextConfiguration
Whether to load the default set of property sources.- Specified by:
isEnableDefaultPropertySources
in interfaceApplicationContextConfiguration
- Returns:
- Returns
true
if the default set of property sources should be loaded.
-
eagerInitAnnotated
@NonNull public @NonNull ApplicationContextBuilder eagerInitAnnotated(Class<? extends Annotation>... annotations) Description copied from interface:ApplicationContextBuilder
Specifies to eager init the given annotated types.- Specified by:
eagerInitAnnotated
in interfaceApplicationContextBuilder
- Parameters:
annotations
- The annotation stereotypes- Returns:
- The context builder
-
overrideConfigLocations
@NonNull public @NonNull ApplicationContextBuilder overrideConfigLocations(String... configLocations) Description copied from interface:ApplicationContextBuilder
Override default config locations.- Specified by:
overrideConfigLocations
in interfaceApplicationContextBuilder
- Parameters:
configLocations
- The config locations- Returns:
- This environment
-
getOverrideConfigLocations
Description copied from interface:ApplicationContextConfiguration
The config locations.- Specified by:
getOverrideConfigLocations
in interfaceApplicationContextConfiguration
- Returns:
- The config locations
-
isBannerEnabled
public boolean isBannerEnabled()Description copied from interface:ApplicationContextConfiguration
The banner is enabled by default.- Specified by:
isBannerEnabled
in interfaceApplicationContextConfiguration
- Returns:
- The banner is enabled by default
-
isBootstrapEnvironmentEnabled
- Specified by:
isBootstrapEnvironmentEnabled
in interfaceApplicationContextConfiguration
-
getEagerInitAnnotated
- Specified by:
getEagerInitAnnotated
in interfaceBeanContextConfiguration
- Returns:
- A set of annotated classes that should be eagerly initialized
-
singletons
Description copied from interface:ApplicationContextBuilder
Additional singletons to register prior to startup.- Specified by:
singletons
in interfaceApplicationContextBuilder
- Parameters:
beans
- The beans- Returns:
- This builder
-
getResourceLoader
Description copied from interface:ApplicationContextConfiguration
The class path resource loader to use.- Specified by:
getResourceLoader
in interfaceApplicationContextConfiguration
- Returns:
- The classpath resource loader
-
getClassLoader
Description copied from interface:BeanContextConfiguration
The class loader to use.- Specified by:
getClassLoader
in interfaceBeanContextConfiguration
- Returns:
- The class loader.
-
deduceEnvironment
@NonNull public @NonNull ApplicationContextBuilder deduceEnvironment(@Nullable @Nullable Boolean deduceEnvironments) Description copied from interface:ApplicationContextBuilder
If set totrue
(the default istrue
) Micronaut will attempt to automatically deduce the environment it is running in using environment variables and/or stack trace inspection.This method differs from
ApplicationContextBuilder.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.- Specified by:
deduceEnvironment
in interfaceApplicationContextBuilder
- Parameters:
deduceEnvironments
- The boolean- Returns:
- This builder
-
deduceCloudEnvironment
Description copied from interface:ApplicationContextBuilder
If set totrue
(the default value isfalse
) 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.
- Specified by:
deduceCloudEnvironment
in interfaceApplicationContextBuilder
- Parameters:
deduceEnvironment
- The boolean- Returns:
- This builder
-
environments
@NonNull public @NonNull ApplicationContextBuilder environments(@Nullable @Nullable String... environments) Description copied from interface:ApplicationContextBuilder
The environments to use.- Specified by:
environments
in interfaceApplicationContextBuilder
- Parameters:
environments
- The environments- Returns:
- This builder
-
defaultEnvironments
@NonNull public @NonNull ApplicationContextBuilder defaultEnvironments(@Nullable @Nullable String... environments) Description copied from interface:ApplicationContextBuilder
The environments to use if no other environments are specified.- Specified by:
defaultEnvironments
in interfaceApplicationContextBuilder
- Parameters:
environments
- The environments- Returns:
- This builder
-
packages
Description copied from interface:ApplicationContextBuilder
The packages to include for package scanning.- Specified by:
packages
in interfaceApplicationContextBuilder
- Parameters:
packages
- The packages- Returns:
- This builder
-
properties
@NonNull public @NonNull ApplicationContextBuilder properties(@Nullable @Nullable Map<String, Object> properties) Description copied from interface:ApplicationContextBuilder
Properties to override from the environment.- Specified by:
properties
in interfaceApplicationContextBuilder
- Parameters:
properties
- The properties- Returns:
- This builder
-
propertySources
@NonNull public @NonNull ApplicationContextBuilder propertySources(@Nullable @Nullable PropertySource... propertySources) Description copied from interface:ApplicationContextBuilder
Additional property sources.- Specified by:
propertySources
in interfaceApplicationContextBuilder
- Parameters:
propertySources
- The property sources to include- Returns:
- This builder
-
environmentPropertySource
@NonNull public @NonNull ApplicationContextBuilder environmentPropertySource(boolean environmentPropertySource) Description copied from interface:ApplicationContextBuilder
Set whether environment variables should contribute to configuration.- Specified by:
environmentPropertySource
in interfaceApplicationContextBuilder
- Parameters:
environmentPropertySource
- The boolean- Returns:
- This builder
-
environmentVariableIncludes
@NonNull public @NonNull ApplicationContextBuilder environmentVariableIncludes(@Nullable @Nullable String... environmentVariables) Description copied from interface:ApplicationContextBuilder
Which environment variables should contribute to configuration.- Specified by:
environmentVariableIncludes
in interfaceApplicationContextBuilder
- Parameters:
environmentVariables
- The environment variables- Returns:
- This builder
-
environmentVariableExcludes
@NonNull public @NonNull ApplicationContextBuilder environmentVariableExcludes(@Nullable @Nullable String... environmentVariables) Description copied from interface:ApplicationContextBuilder
Which environment variables should not contribute to configuration.- Specified by:
environmentVariableExcludes
in interfaceApplicationContextBuilder
- Parameters:
environmentVariables
- The environment variables- Returns:
- This builder
-
getDeduceEnvironments
Description copied from interface:ApplicationContextConfiguration
If set totrue
(the default istrue
) Micronaut will attempt to automatically deduce the environment it is running in using environment variables and/or stack trace inspection.This method differs from
ApplicationContextConfiguration.isDeduceCloudEnvironment()
which controls whether network and/or disk probes are performed to try and automatically establish the Cloud environment.This behaviour controls the automatic activation of, for example, the
Environment.TEST
when running tests.- Specified by:
getDeduceEnvironments
in interfaceApplicationContextConfiguration
- Returns:
- True if the environments should be deduced
-
isDeduceCloudEnvironment
public boolean isDeduceCloudEnvironment()Description copied from interface:ApplicationContextConfiguration
If set totrue
Micronaut will attempt to deduce the environment using safe methods like environment variables and the stack trace.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.
- Specified by:
isDeduceCloudEnvironment
in interfaceApplicationContextConfiguration
- Returns:
- True if the environments should be deduced
-
getEnvironments
- Specified by:
getEnvironments
in interfaceApplicationContextConfiguration
- Returns:
- The environment names
-
getDefaultEnvironments
- Specified by:
getDefaultEnvironments
in interfaceApplicationContextConfiguration
- Returns:
- The default environments to be applied if no other environments are explicitly specified or deduced.
-
isEnvironmentPropertySource
public boolean isEnvironmentPropertySource()- Specified by:
isEnvironmentPropertySource
in interfaceApplicationContextConfiguration
- Returns:
- True if environment variables should contribute to configuration
-
getEnvironmentVariableIncludes
- Specified by:
getEnvironmentVariableIncludes
in interfaceApplicationContextConfiguration
- Returns:
- The environment variables to include in configuration
-
getEnvironmentVariableExcludes
- Specified by:
getEnvironmentVariableExcludes
in interfaceApplicationContextConfiguration
- Returns:
- The environment variables to exclude from configuration
-
mainClass
Description copied from interface:ApplicationContextBuilder
The main class used by this application.- Specified by:
mainClass
in interfaceApplicationContextBuilder
- Parameters:
mainClass
- The main class- Returns:
- This builder
-
classLoader
Description copied from interface:ApplicationContextBuilder
The class loader to be used.- Specified by:
classLoader
in interfaceApplicationContextBuilder
- Parameters:
classLoader
- The classloader- Returns:
- This builder
-
args
Description copied from interface:ApplicationContextBuilder
Set the command line arguments.- Specified by:
args
in interfaceApplicationContextBuilder
- Parameters:
args
- The arguments- Returns:
- This application
-
bootstrapEnvironment
Description copied from interface:ApplicationContextBuilder
Sets whether the bootstrap environment should be initialized.- Specified by:
bootstrapEnvironment
in interfaceApplicationContextBuilder
- Parameters:
bootstrapEnv
- True if it should be initialized. Default true- Returns:
- This application
-
build
Description copied from interface:ApplicationContextBuilder
Builds theApplicationContext
, but does not start it.- Specified by:
build
in interfaceApplicationContextBuilder
- Returns:
- The built, but not running
ApplicationContext
-
newApplicationContext
Creates theApplicationContext
instance.- Returns:
- The application context
- Since:
- 2.0
-
include
@NonNull public @NonNull ApplicationContextBuilder include(@Nullable @Nullable String... configurations) Allow customizing the configurations that will be loaded.- Specified by:
include
in interfaceApplicationContextBuilder
- Parameters:
configurations
- The configurations to include- Returns:
- This application
-
exclude
@NonNull public @NonNull ApplicationContextBuilder exclude(@Nullable @Nullable String... configurations) Allow customizing the configurations that will be loaded.- Specified by:
exclude
in interfaceApplicationContextBuilder
- Parameters:
configurations
- The configurations to exclude- Returns:
- This application
-
banner
Description copied from interface:ApplicationContextBuilder
Whether the banner is enabled or not.- Specified by:
banner
in interfaceApplicationContextBuilder
- Parameters:
isEnabled
- Whether the banner is enabled or not- Returns:
- This application
-
allowEmptyProviders
Description copied from interface:ApplicationContextBuilder
Whether to error on an empty bean provider. Defaults tofalse
.- Specified by:
allowEmptyProviders
in interfaceApplicationContextBuilder
- Parameters:
shouldAllow
- True if emptyProvider
instances are allowed- Returns:
- This application
-