Package io.micronaut.context
Interface ApplicationContextBuilder
- All Known Implementing Classes:
DefaultApplicationContextBuilder,Micronaut
public interface ApplicationContextBuilder
An interface for building an application context.
- Since:
- 1.0
- Author:
- graemerocher
- See Also:
-
Method Summary
Modifier and TypeMethodDescription@NonNull ApplicationContextBuilderallowEmptyProviders(boolean shouldAllow) Whether to error on an empty bean provider.default @NonNull ApplicationContextBuilderSet the command line arguments.@NonNull ApplicationContextBuilderbanner(boolean isEnabled) Whether the banner is enabled or not.default @NonNull ApplicationContextBuilderbeanConfigurations(@NonNull BeanConfiguration... configurations) Register additional bean configurations.default @NonNull ApplicationContextBuilderbeanDefinitions(@NonNull RuntimeBeanDefinition<?>... definitions) Register additional runtime bean definitions prior to startup.default @NonNull ApplicationContextBuilderbeanDefinitionsProvider(@NonNull BeanDefinitionsProvider provider) Override the defaultBeanDefinitionsProvider.default @NonNull ApplicationContextBuilderbeanResolutionTrace(@NonNull BeanResolutionTraceConfiguration configuration) Sets the trace mode for bean resolution.default @NonNull ApplicationContextBuilderbeanResolutionTrace(@NonNull BeanResolutionTraceMode traceMode, String... classPatterns) Sets the trace mode for bean resolution.@NonNull ApplicationContextBuilderbeansPredicate(@Nullable Predicate<QualifiedBeanType<?>> predicate) Set a predicate to filter beans considered by the context.default @NonNull ApplicationContextBuilderbootstrapEnvironment(boolean bootstrapEnv) Sets whether the bootstrap environment should be initialized.@NonNull ApplicationContextbuild()Builds theApplicationContext, but does not start it.@NonNull ApplicationContextBuilderclassLoader(@Nullable ClassLoader classLoader) The class loader to be used.@NonNull ApplicationContextBuilderdeduceCloudEnvironment(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 deduceEnvironment) 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.@NonNull ApplicationContextBuilderdeducePackage(@org.jspecify.annotations.Nullable 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.@NonNull ApplicationContextBuildereagerBeansEnabled(boolean enabled) Disable eager beans functionality.@NonNull ApplicationContextBuildereagerInitAnnotated(Class<? extends Annotation>... annotations) Specifies to eager init the given annotated types.default @NonNull ApplicationContextBuildereagerInitConfiguration(boolean eagerInitConfiguration) Whether to eager initializeConfigurationPropertiesbeans.default @NonNull ApplicationContextBuildereagerInitSingletons(boolean eagerInitSingletons) Whether to eager initialize singleton beans.default @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.@NonNull ApplicationContextBuildereventsEnabled(boolean enabled) Enable or disable application events publishing.@NonNull ApplicationContextBuilderAllow customizing the configurations that will be loaded.@NonNull ApplicationContextBuilderAllow customizing the configurations that will be loaded.@NonNull ApplicationContextBuilderThe main class used by this application.@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.@NonNull ApplicationContextBuilderresourceResolver(@Nullable ClassPathResourceLoader resourceResolver) Sets the class path resource resolver for the application context builder.default <T extends AutoCloseable>
@NonNull TRun theApplicationContextwith the given type.@NonNull ApplicationContextBuildersingletons(@Nullable Object... beans) Additional singletons to register prior to startup.default @NonNull ApplicationContextstart()Starts theApplicationContext.
-
Method Details
-
beanResolutionTrace
default @NonNull ApplicationContextBuilder beanResolutionTrace(@NonNull BeanResolutionTraceMode traceMode, String... classPatterns) Sets the trace mode for bean resolution.- Parameters:
traceMode- The debug modeclassPatterns- The patterns- Returns:
- This builder
- Since:
- 4.8.0
- See Also:
-
beanResolutionTrace
default @NonNull ApplicationContextBuilder beanResolutionTrace(@NonNull BeanResolutionTraceConfiguration configuration) Sets the trace mode for bean resolution.- Parameters:
configuration- The trace configuration- Returns:
- This builder
- Since:
- 4.8.0
- See Also:
-
eagerInitConfiguration
Whether to eager initializeConfigurationPropertiesbeans.- Parameters:
eagerInitConfiguration- True if configuration properties should be eagerly initialized- Returns:
- The context builder
- Since:
- 2.0
-
eagerInitSingletons
Whether to eager initialize singleton beans.- Parameters:
eagerInitSingletons- True if singletons should be eagerly initialized- Returns:
- The context builder
- Since:
- 2.0
-
enableDefaultPropertySources
Specify whether the default set of property sources should be enabled (default istrue).- Parameters:
areEnabled- Whether the default property sources are enabled- Returns:
- This builder
- Since:
- 3.7.0
-
eagerInitAnnotated
Specifies to eager init the given annotated types.- Parameters:
annotations- The annotation stereotypes- Returns:
- The context builder
- Since:
- 2.0
-
overrideConfigLocations
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
-
beanDefinitions
default @NonNull ApplicationContextBuilder beanDefinitions(@NonNull RuntimeBeanDefinition<?>... definitions) Register additional runtime bean definitions prior to startup.- Parameters:
definitions- The definitions.- Returns:
- The context builder
- Since:
- 4.5.0
-
beanConfigurations
default @NonNull ApplicationContextBuilder beanConfigurations(@NonNull BeanConfiguration... configurations) Register additional bean configurations.- Parameters:
configurations- The configurations.- Returns:
- This builder
- Since:
- 4.8.0
-
deduceEnvironment
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
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.- Parameters:
deduceEnvironment- The boolean- Returns:
- This builder
-
deducePackage
@NonNull ApplicationContextBuilder deducePackage(@org.jspecify.annotations.Nullable boolean deducePackage) If the package should be deduced from the stack trace. (default istrue)- Parameters:
deducePackage- The boolean- Returns:
- This builder
- Since:
- 5.0
-
deduceCloudEnvironment
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.
- Parameters:
deduceEnvironment- The boolean- Returns:
- This builder
- Since:
- 4.0.0
-
environments
The environments to use.- Parameters:
environments- The environments- Returns:
- This builder
-
defaultEnvironments
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
Additional property sources.- Parameters:
propertySources- The property sources to include- Returns:
- This builder
-
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
@NonNull ApplicationContext build()Builds theApplicationContext, but does not start it.- Returns:
- The built, but not running
ApplicationContext
-
include
Allow customizing the configurations that will be loaded.- Parameters:
configurations- The configurations to include- Returns:
- This application
-
exclude
Allow customizing the configurations that will be loaded.- Parameters:
configurations- The configurations to exclude- Returns:
- This application
-
banner
Whether the banner is enabled or not.- Parameters:
isEnabled- Whether the banner is enabled or not- Returns:
- This application
-
allowEmptyProviders
Whether to error on an empty bean provider. Defaults tofalse.- Parameters:
shouldAllow- True if emptyProviderinstances are allowed- Returns:
- This application
- Since:
- 3.0.0
-
args
Set the command line arguments.- Parameters:
args- The arguments- Returns:
- This application
-
bootstrapEnvironment
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
-
beanDefinitionsProvider
default @NonNull ApplicationContextBuilder beanDefinitionsProvider(@NonNull BeanDefinitionsProvider provider) Override the defaultBeanDefinitionsProvider.- Parameters:
provider- The bean definitions provider to be used.- Returns:
- This builder instance for method chaining.
- Since:
- 5.0
-
eagerBeansEnabled
Disable eager beans functionality.- Parameters:
enabled- True to enable eager beans; false to disable- Returns:
- This builder
- Since:
- 5.0
-
eventsEnabled
Enable or disable application events publishing.- Parameters:
enabled- True to enable events; false to disable- Returns:
- This builder
- Since:
- 5.0
-
beansPredicate
@NonNull ApplicationContextBuilder beansPredicate(@Nullable Predicate<QualifiedBeanType<?>> predicate) Set a predicate to filter beans considered by the context.- Parameters:
predicate- The predicate to apply, or null to clear it- Returns:
- This builder
- Since:
- 5.0
-
resourceResolver
@NonNull ApplicationContextBuilder resourceResolver(@Nullable ClassPathResourceLoader resourceResolver) Sets the class path resource resolver for the application context builder.- Parameters:
resourceResolver- the class path resource resolver- Returns:
- This builder
- Since:
- 5.0
-
start
Starts theApplicationContext.- Returns:
- The running
ApplicationContext
-
run
Run theApplicationContextwith the given type. Returning an instance of the type.- Type Parameters:
T- The type, a subclass ofAutoCloseable. The close method of the implementation should shut down the context.- Parameters:
type- The type of the bean to run- Returns:
- The running bean
-