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 TypeMethodDescription@NonNull ApplicationContextBuilderallowEmptyProviders(boolean shouldAllow) Whether to error on an empty bean provider.@NonNull ApplicationContextBuilderSet the command line arguments.@NonNull ApplicationContextBuilderbanner(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.@NonNull ApplicationContextBuilderOverride the defaultBeanDefinitionsProvider.beanResolutionTrace(BeanResolutionTraceConfiguration configuration) Sets the trace mode for bean resolution.@NonNull ApplicationContextBuilderbeansPredicate(@Nullable Predicate<QualifiedBeanType<?>> predicate) Set a predicate to filter beans considered by the context.@NonNull ApplicationContextBuilderbootstrapEnvironment(boolean bootstrapEnv) Sets whether the bootstrap environment should be initialized.@NonNull ApplicationContextbuild()Builds theApplicationContext, but does not start it.@NonNull ApplicationContextBuilderclassLoader(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.@NonNull ApplicationContextBuilderdeduceEnvironment(@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.deducePackage(boolean deducePackage) If the package should be deduced from the stack trace.@NonNull ApplicationContextBuilderdefaultEnvironments(@Nullable String... environments) The environments to use if no other environments are specified.boolean@NonNull ApplicationContextBuildereagerBeansEnabled(boolean enabled) Disable eager beans functionality.@NonNull ApplicationContextBuildereagerInitAnnotated(Class<? extends Annotation>... annotations) Specifies to eager init the given annotated types.@NonNull ApplicationContextBuilderenableDefaultPropertySources(boolean areEnabled) Specify whether the default set of property sources should be enabled (default istrue).@NonNull ApplicationContextBuilderenvironmentPropertySource(boolean environmentPropertySource) Set whether environment variables should contribute to configuration.@NonNull ApplicationContextBuilderenvironments(@Nullable String... environments) The environments to use.@NonNull ApplicationContextBuilderenvironmentVariableExcludes(@Nullable String... environmentVariables) Which environment variables should not contribute to configuration.@NonNull ApplicationContextBuilderenvironmentVariableIncludes(@Nullable String... environmentVariables) Which environment variables should contribute to configuration.boolean@NonNull ApplicationContextBuildereventsEnabled(boolean enabled) Enable or disable application events publishing.@NonNull ApplicationContextBuilderAllow customizing the configurations that will be loaded.@NonNull ClassLoaderThe 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.@NonNull ClassPathResourceLoaderThe class path resource loader to use.The debug mode for bean resolution.@NonNull ApplicationContextBuilderAllow customizing the configurations that will be loaded.booleanbooleanThe banner is enabled by default.@Nullable BooleanbooleanIf set totrueMicronaut will attempt to deduce the environment using safe methods like environment variables and the stack trace.booleanIf set totrue(the default istrue) Micronaut will attempt to automatically deduce the user package.booleanWhether to load the default set of property sources.boolean@NonNull ApplicationContextBuilderThe main class used by this application.protected @NonNull ApplicationContextCreates theApplicationContextinstance.@NonNull ApplicationContextBuilderoverrideConfigLocations(String... configLocations) Override default config locations.@NonNull ApplicationContextBuilderThe packages to include for package scanning.@NonNull ApplicationContextBuilderproperties(@Nullable Map<String, Object> properties) Properties to override from the environment.@NonNull ApplicationContextBuilderpropertySources(@Nullable PropertySource... propertySources) Additional property sources.resourceResolver(ClassPathResourceLoader resourceResolver) Sets the class path resource resolver for the application context builder.@NonNull ApplicationContextBuildersingletons(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
getApplicationName, getConversionService, getEnvironmentNamesDeducer, getPackageDeducer, getPropertySourcesLocatorsMethods 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
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
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
-
getBeanDefinitionsProvider
- Specified by:
getBeanDefinitionsProviderin interfaceBeanContextConfiguration- Returns:
- Bean definitions provider.
-
eagerBeansEnabled
public boolean eagerBeansEnabled()- Specified by:
eagerBeansEnabledin interfaceBeanContextConfiguration- Returns:
- Are eager beans enabled.
-
eventsEnabled
public boolean eventsEnabled()- Specified by:
eventsEnabledin interfaceBeanContextConfiguration- Returns:
- Are events enabled.
-
beansPredicate
- Specified by:
beansPredicatein interfaceBeanContextConfiguration- Returns:
- Beans predicate.
-
singletons
Description copied from interface:ApplicationContextBuilderAdditional singletons to register prior to startup.- Specified by:
singletonsin interfaceApplicationContextBuilder- Parameters:
beans- The beans- Returns:
- This builder
-
beanDefinitions
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
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
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
-
deducePackage
Description copied from interface:ApplicationContextBuilderIf the package should be deduced from the stack trace. (default istrue)- Specified by:
deducePackagein interfaceApplicationContextBuilder- Parameters:
deducePackage- 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
Description copied from interface:ApplicationContextBuilderThe environments to use.- Specified by:
environmentsin interfaceApplicationContextBuilder- Parameters:
environments- The environments- Returns:
- This builder
-
defaultEnvironments
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
Description copied from interface:ApplicationContextBuilderProperties to override from the environment.- Specified by:
propertiesin interfaceApplicationContextBuilder- Parameters:
properties- The properties- Returns:
- This builder
-
propertySources
public @NonNull ApplicationContextBuilder propertySources(@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
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
public @NonNull ApplicationContextBuilder environmentVariableIncludes(@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
public @NonNull ApplicationContextBuilder environmentVariableExcludes(@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
-
isDeducePackage
public boolean isDeducePackage()Description copied from interface:ApplicationContextConfigurationIf set totrue(the default istrue) Micronaut will attempt to automatically deduce the user package. Alternative is to useEnvironment.addPackage(String)- Specified by:
isDeducePackagein interfaceApplicationContextConfiguration- Returns:
- True if the package 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
-
beanDefinitionsProvider
Description copied from interface:ApplicationContextBuilderOverride the defaultBeanDefinitionsProvider.- Specified by:
beanDefinitionsProviderin interfaceApplicationContextBuilder- Parameters:
provider- The bean definitions provider to be used.- Returns:
- This builder instance for method chaining.
-
eagerBeansEnabled
Description copied from interface:ApplicationContextBuilderDisable eager beans functionality.- Specified by:
eagerBeansEnabledin interfaceApplicationContextBuilder- Parameters:
enabled- True to enable eager beans; false to disable- Returns:
- This builder
-
eventsEnabled
Description copied from interface:ApplicationContextBuilderEnable or disable application events publishing.- Specified by:
eventsEnabledin interfaceApplicationContextBuilder- Parameters:
enabled- True to enable events; false to disable- Returns:
- This builder
-
beansPredicate
public @NonNull ApplicationContextBuilder beansPredicate(@Nullable Predicate<QualifiedBeanType<?>> predicate) Description copied from interface:ApplicationContextBuilderSet a predicate to filter beans considered by the context.- Specified by:
beansPredicatein interfaceApplicationContextBuilder- Parameters:
predicate- The predicate to apply, or null to clear it- Returns:
- This builder
-
resourceResolver
Description copied from interface:ApplicationContextBuilderSets the class path resource resolver for the application context builder.- Specified by:
resourceResolverin interfaceApplicationContextBuilder- Parameters:
resourceResolver- the class path resource resolver- Returns:
- This builder
-
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
Allow customizing the configurations that will be loaded.- Specified by:
includein interfaceApplicationContextBuilder- Parameters:
configurations- The configurations to include- Returns:
- This application
-
exclude
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
-