Class DefaultApplicationContextBuilder
- All Implemented Interfaces:
ApplicationContextBuilder,ApplicationContextConfiguration,BeanContextConfiguration
- Direct Known Subclasses:
Micronaut
ApplicationContextBuilder.- Since:
- 1.0
- Author:
- graemerocher
-
Constructor Summary
Constructors -
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.beanConfigurations(@NonNull BeanConfiguration... configurations) Register additional bean configurations.beanDefinitions(@NonNull RuntimeBeanDefinition<?>... definitions) Register additional runtime bean definitions prior to startup.beanResolutionTrace(BeanResolutionTraceConfiguration configuration) Sets the trace mode for bean resolution.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.The loadedApplicationContextConfigurer.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.The debug mode for bean resolution.Allow customizing the configurations that will be loaded.booleanbooleanThe banner is enabled by default.booleanIf set totrueMicronaut will attempt to deduce the environment using safe methods like environment variables and the stack trace.booleanWhether to load the default set of property sources.booleanThe main class used by this application.protected @NonNull ApplicationContextCreates theApplicationContextinstance.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, waitMethods inherited from interface io.micronaut.context.ApplicationContextBuilder
beanResolutionTrace, eagerInitConfiguration, eagerInitSingletons, run, startMethods inherited from interface io.micronaut.context.ApplicationContextConfiguration
getConversionServiceMethods inherited from interface io.micronaut.context.BeanContextConfiguration
isEagerInitConfiguration, isEagerInitSingletons
-
Constructor Details
-
DefaultApplicationContextBuilder
protected DefaultApplicationContextBuilder()Default constructor.
-
-
Method Details
-
beanResolutionTrace
public ApplicationContextBuilder beanResolutionTrace(BeanResolutionTraceConfiguration configuration) Description copied from interface:ApplicationContextBuilderSets the trace mode for bean resolution.- Specified by:
beanResolutionTracein interfaceApplicationContextBuilder- Parameters:
configuration- The trace configuration- Returns:
- This builder
- See Also:
-
getTraceConfiguration
Description copied from interface:BeanContextConfigurationThe debug mode for bean resolution.- Specified by:
getTraceConfigurationin interfaceBeanContextConfiguration- Returns:
- The bean resolution debug mode.
- See Also:
-
getContextConfigurer
Description copied from interface:ApplicationContextConfigurationThe loadedApplicationContextConfigurer.- Specified by:
getContextConfigurerin interfaceApplicationContextConfiguration- Returns:
- The context configurer.
-
isAllowEmptyProviders
public boolean isAllowEmptyProviders()- Specified by:
isAllowEmptyProvidersin interfaceBeanContextConfiguration- Returns:
- If a
NoSuchBeanExceptionshould be thrown on a missingBeanProviderorProvider
-
enableDefaultPropertySources
Description copied from interface:ApplicationContextBuilderSpecify whether the default set of property sources should be enabled (default istrue).- Specified by:
enableDefaultPropertySourcesin interfaceApplicationContextBuilder- Parameters:
areEnabled- Whether the default property sources are enabled- Returns:
- This builder
-
isEnableDefaultPropertySources
public boolean isEnableDefaultPropertySources()Description copied from interface:ApplicationContextConfigurationWhether to load the default set of property sources.- Specified by:
isEnableDefaultPropertySourcesin interfaceApplicationContextConfiguration- Returns:
- Returns
trueif the default set of property sources should be loaded.
-
eagerInitAnnotated
@NonNull public @NonNull ApplicationContextBuilder eagerInitAnnotated(Class<? extends Annotation>... annotations) Description copied from interface:ApplicationContextBuilderSpecifies to eager init the given annotated types.- Specified by:
eagerInitAnnotatedin interfaceApplicationContextBuilder- Parameters:
annotations- The annotation stereotypes- Returns:
- The context builder
-
overrideConfigLocations
@NonNull public @NonNull ApplicationContextBuilder overrideConfigLocations(String... configLocations) Description copied from interface:ApplicationContextBuilderOverride default config locations.- Specified by:
overrideConfigLocationsin interfaceApplicationContextBuilder- Parameters:
configLocations- The config locations- Returns:
- This environment
-
getOverrideConfigLocations
Description copied from interface:ApplicationContextConfigurationThe config locations.- Specified by:
getOverrideConfigLocationsin interfaceApplicationContextConfiguration- Returns:
- The config locations
-
isBannerEnabled
public boolean isBannerEnabled()Description copied from interface:ApplicationContextConfigurationThe banner is enabled by default.- Specified by:
isBannerEnabledin interfaceApplicationContextConfiguration- Returns:
- The banner is enabled by default
-
isBootstrapEnvironmentEnabled
- Specified by:
isBootstrapEnvironmentEnabledin interfaceApplicationContextConfiguration
-
getEagerInitAnnotated
- Specified by:
getEagerInitAnnotatedin interfaceBeanContextConfiguration- Returns:
- A set of annotated classes that should be eagerly initialized
-
singletons
Description copied from interface:ApplicationContextBuilderAdditional singletons to register prior to startup.- Specified by:
singletonsin interfaceApplicationContextBuilder- Parameters:
beans- The beans- Returns:
- This builder
-
beanDefinitions
public ApplicationContextBuilder beanDefinitions(@NonNull @NonNull RuntimeBeanDefinition<?>... definitions) Description copied from interface:ApplicationContextBuilderRegister additional runtime bean definitions prior to startup.- Specified by:
beanDefinitionsin interfaceApplicationContextBuilder- Parameters:
definitions- The definitions.- Returns:
- The context builder
-
beanConfigurations
public ApplicationContextBuilder beanConfigurations(@NonNull @NonNull BeanConfiguration... configurations) Description copied from interface:ApplicationContextBuilderRegister additional bean configurations.- Specified by:
beanConfigurationsin interfaceApplicationContextBuilder- Parameters:
configurations- The configurations.- Returns:
- This builder
-
getResourceLoader
Description copied from interface:ApplicationContextConfigurationThe class path resource loader to use.- Specified by:
getResourceLoaderin interfaceApplicationContextConfiguration- Returns:
- The classpath resource loader
-
getClassLoader
Description copied from interface:BeanContextConfigurationThe class loader to use.- Specified by:
getClassLoaderin interfaceBeanContextConfiguration- Returns:
- The class loader.
-
deduceEnvironment
@NonNull public @NonNull ApplicationContextBuilder deduceEnvironment(@Nullable @Nullable Boolean deduceEnvironments) Description copied from interface:ApplicationContextBuilderIf 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.TESTwhen running tests.- Specified by:
deduceEnvironmentin interfaceApplicationContextBuilder- Parameters:
deduceEnvironments- The boolean- Returns:
- This builder
-
deduceCloudEnvironment
Description copied from interface:ApplicationContextBuilderIf 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:
deduceCloudEnvironmentin interfaceApplicationContextBuilder- Parameters:
deduceEnvironment- The boolean- Returns:
- This builder
-
environments
@NonNull public @NonNull ApplicationContextBuilder environments(@Nullable @Nullable String... environments) Description copied from interface:ApplicationContextBuilderThe environments to use.- Specified by:
environmentsin interfaceApplicationContextBuilder- Parameters:
environments- The environments- Returns:
- This builder
-
defaultEnvironments
@NonNull public @NonNull ApplicationContextBuilder defaultEnvironments(@Nullable @Nullable String... environments) Description copied from interface:ApplicationContextBuilderThe environments to use if no other environments are specified.- Specified by:
defaultEnvironmentsin interfaceApplicationContextBuilder- Parameters:
environments- The environments- Returns:
- This builder
-
packages
Description copied from interface:ApplicationContextBuilderThe packages to include for package scanning.- Specified by:
packagesin interfaceApplicationContextBuilder- Parameters:
packages- The packages- Returns:
- This builder
-
properties
@NonNull public @NonNull ApplicationContextBuilder properties(@Nullable @Nullable Map<String, Object> properties) Description copied from interface:ApplicationContextBuilderProperties to override from the environment.- Specified by:
propertiesin interfaceApplicationContextBuilder- Parameters:
properties- The properties- Returns:
- This builder
-
propertySources
@NonNull public @NonNull ApplicationContextBuilder propertySources(@Nullable @Nullable PropertySource... propertySources) Description copied from interface:ApplicationContextBuilderAdditional property sources.- Specified by:
propertySourcesin interfaceApplicationContextBuilder- Parameters:
propertySources- The property sources to include- Returns:
- This builder
-
environmentPropertySource
@NonNull public @NonNull ApplicationContextBuilder environmentPropertySource(boolean environmentPropertySource) Description copied from interface:ApplicationContextBuilderSet whether environment variables should contribute to configuration.- Specified by:
environmentPropertySourcein interfaceApplicationContextBuilder- Parameters:
environmentPropertySource- The boolean- Returns:
- This builder
-
environmentVariableIncludes
@NonNull public @NonNull ApplicationContextBuilder environmentVariableIncludes(@Nullable @Nullable String... environmentVariables) Description copied from interface:ApplicationContextBuilderWhich environment variables should contribute to configuration.- Specified by:
environmentVariableIncludesin interfaceApplicationContextBuilder- Parameters:
environmentVariables- The environment variables- Returns:
- This builder
-
environmentVariableExcludes
@NonNull public @NonNull ApplicationContextBuilder environmentVariableExcludes(@Nullable @Nullable String... environmentVariables) Description copied from interface:ApplicationContextBuilderWhich environment variables should not contribute to configuration.- Specified by:
environmentVariableExcludesin interfaceApplicationContextBuilder- Parameters:
environmentVariables- The environment variables- Returns:
- This builder
-
getDeduceEnvironments
Description copied from interface:ApplicationContextConfigurationIf 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.TESTwhen running tests.- Specified by:
getDeduceEnvironmentsin interfaceApplicationContextConfiguration- Returns:
- True if the environments should be deduced
-
isDeduceCloudEnvironment
public boolean isDeduceCloudEnvironment()Description copied from interface:ApplicationContextConfigurationIf set totrueMicronaut 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:
isDeduceCloudEnvironmentin interfaceApplicationContextConfiguration- Returns:
- True if the environments should be deduced
-
getEnvironments
- Specified by:
getEnvironmentsin interfaceApplicationContextConfiguration- Returns:
- The environment names
-
getDefaultEnvironments
- Specified by:
getDefaultEnvironmentsin interfaceApplicationContextConfiguration- Returns:
- The default environments to be applied if no other environments are explicitly specified or deduced.
-
isEnvironmentPropertySource
public boolean isEnvironmentPropertySource()- Specified by:
isEnvironmentPropertySourcein interfaceApplicationContextConfiguration- Returns:
- True if environment variables should contribute to configuration
-
getEnvironmentVariableIncludes
- Specified by:
getEnvironmentVariableIncludesin interfaceApplicationContextConfiguration- Returns:
- The environment variables to include in configuration
-
getEnvironmentVariableExcludes
- Specified by:
getEnvironmentVariableExcludesin interfaceApplicationContextConfiguration- Returns:
- The environment variables to exclude from configuration
-
mainClass
Description copied from interface:ApplicationContextBuilderThe main class used by this application.- Specified by:
mainClassin interfaceApplicationContextBuilder- Parameters:
mainClass- The main class- Returns:
- This builder
-
classLoader
Description copied from interface:ApplicationContextBuilderThe class loader to be used.- Specified by:
classLoaderin interfaceApplicationContextBuilder- Parameters:
classLoader- The classloader- Returns:
- This builder
-
args
Description copied from interface:ApplicationContextBuilderSet the command line arguments.- Specified by:
argsin interfaceApplicationContextBuilder- Parameters:
args- The arguments- Returns:
- This application
-
bootstrapEnvironment
Description copied from interface:ApplicationContextBuilderSets whether the bootstrap environment should be initialized.- Specified by:
bootstrapEnvironmentin interfaceApplicationContextBuilder- Parameters:
bootstrapEnv- True if it should be initialized. Default true- Returns:
- This application
-
build
Description copied from interface:ApplicationContextBuilderBuilds theApplicationContext, but does not start it.- Specified by:
buildin interfaceApplicationContextBuilder- Returns:
- The built, but not running
ApplicationContext
-
newApplicationContext
Creates theApplicationContextinstance.- 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:
includein 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:
excludein interfaceApplicationContextBuilder- Parameters:
configurations- The configurations to exclude- Returns:
- This application
-
banner
Description copied from interface:ApplicationContextBuilderWhether the banner is enabled or not.- Specified by:
bannerin interfaceApplicationContextBuilder- Parameters:
isEnabled- Whether the banner is enabled or not- Returns:
- This application
-
allowEmptyProviders
Description copied from interface:ApplicationContextBuilderWhether to error on an empty bean provider. Defaults tofalse.- Specified by:
allowEmptyProvidersin interfaceApplicationContextBuilder- Parameters:
shouldAllow- True if emptyProviderinstances are allowed- Returns:
- This application
-