Package io.micronaut.context
Interface ApplicationContextBuilder
-
- All Known Implementing Classes:
DefaultApplicationContextBuilder
public interface ApplicationContextBuilderAn interface for building an application context.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ApplicationContextBuilderallowEmptyProviders(boolean shouldAllow)Whether to error on an empty bean provider.default ApplicationContextBuilderargs(java.lang.String... args)Set the command line arguments.ApplicationContextBuilderbanner(boolean isEnabled)Whether the banner is enabled or not.default ApplicationContextBuilderbootstrapEnvironment(boolean bootstrapEnv)Sets whether the bootstrap environment should be initialized.ApplicationContextbuild()Builds theApplicationContext, but does not start it.ApplicationContextBuilderclassLoader(java.lang.ClassLoader classLoader)The class loader to be used.ApplicationContextBuilderdeduceEnvironment(java.lang.Boolean deduceEnvironment)Whether to deduce environments.ApplicationContextBuilderdefaultEnvironments(java.lang.String... environments)The environments to use if no other environments are specified.ApplicationContextBuildereagerInitAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)Specifies to eager init the given annotated types.default ApplicationContextBuildereagerInitConfiguration(boolean eagerInitConfiguration)Whether to eager initializeConfigurationPropertiesbeans.default ApplicationContextBuildereagerInitSingletons(boolean eagerInitSingletons)Whether to eager initialize singleton beans.ApplicationContextBuilderenvironmentPropertySource(boolean environmentPropertySource)Set whether environment variables should contribute to configuration.ApplicationContextBuilderenvironments(java.lang.String... environments)The environments to use.ApplicationContextBuilderenvironmentVariableExcludes(java.lang.String... environmentVariables)Which environment variables should not contribute to configuration.ApplicationContextBuilderenvironmentVariableIncludes(java.lang.String... environmentVariables)Which environment variables should contribute to configuration.ApplicationContextBuilderexclude(java.lang.String... configurations)Allow customizing the configurations that will be loaded.ApplicationContextBuilderinclude(java.lang.String... configurations)Allow customizing the configurations that will be loaded.ApplicationContextBuildermainClass(java.lang.Class mainClass)The main class used by this application.ApplicationContextBuilderoverrideConfigLocations(java.lang.String... configLocations)Override default config locations.ApplicationContextBuilderpackages(java.lang.String... packages)The packages to include for package scanning.ApplicationContextBuilderproperties(java.util.Map<java.lang.String,java.lang.Object> properties)Properties to override from the environment.ApplicationContextBuilderpropertySources(PropertySource... propertySources)Additional property sources.default <T extends java.lang.AutoCloseable>
Trun(java.lang.Class<T> type)Run theApplicationContextwith the given type.ApplicationContextBuildersingletons(java.lang.Object... beans)Additional singletons to register prior to startup.default ApplicationContextstart()Starts theApplicationContext.
-
-
-
Method Detail
-
eagerInitConfiguration
@NonNull default ApplicationContextBuilder eagerInitConfiguration(boolean eagerInitConfiguration)
Whether to eager initializeConfigurationPropertiesbeans.- 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
-
eagerInitAnnotated
@NonNull ApplicationContextBuilder eagerInitAnnotated(java.lang.Class<? extends java.lang.annotation.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(java.lang.String... configLocations)
Override default config locations.- Parameters:
configLocations- The config locations- Returns:
- This environment
- Since:
- 2.0
-
singletons
@NonNull ApplicationContextBuilder singletons(@Nullable java.lang.Object... beans)
Additional singletons to register prior to startup.- Parameters:
beans- The beans- Returns:
- This builder
-
deduceEnvironment
@NonNull ApplicationContextBuilder deduceEnvironment(@Nullable java.lang.Boolean deduceEnvironment)
Whether to deduce environments.- Parameters:
deduceEnvironment- The boolean- Returns:
- This builder
-
environments
@NonNull ApplicationContextBuilder environments(@Nullable java.lang.String... environments)
The environments to use.- Parameters:
environments- The environments- Returns:
- This builder
-
defaultEnvironments
@NonNull ApplicationContextBuilder defaultEnvironments(@Nullable java.lang.String... environments)
The environments to use if no other environments are specified.- Parameters:
environments- The environments- Returns:
- This builder
-
packages
@NonNull ApplicationContextBuilder packages(@Nullable java.lang.String... packages)
The packages to include for package scanning.- Parameters:
packages- The packages- Returns:
- This builder
-
properties
@NonNull ApplicationContextBuilder properties(@Nullable java.util.Map<java.lang.String,java.lang.Object> 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 java.lang.String... environmentVariables)
Which environment variables should contribute to configuration.- Parameters:
environmentVariables- The environment variables- Returns:
- This builder
-
environmentVariableExcludes
@NonNull ApplicationContextBuilder environmentVariableExcludes(@Nullable java.lang.String... environmentVariables)
Which environment variables should not contribute to configuration.- Parameters:
environmentVariables- The environment variables- Returns:
- This builder
-
mainClass
@NonNull ApplicationContextBuilder mainClass(@Nullable java.lang.Class mainClass)
The main class used by this application.- Parameters:
mainClass- The main class- Returns:
- This builder
-
classLoader
@NonNull ApplicationContextBuilder classLoader(@Nullable java.lang.ClassLoader 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
@NonNull ApplicationContextBuilder include(@Nullable java.lang.String... configurations)
Allow customizing the configurations that will be loaded.- Parameters:
configurations- The configurations to include- Returns:
- This application
-
exclude
@NonNull ApplicationContextBuilder exclude(@Nullable java.lang.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 tofalse.- Parameters:
shouldAllow- True if emptyProviderinstances are allowed- Returns:
- This application
- Since:
- 3.0.0
-
args
@NonNull default ApplicationContextBuilder args(@Nullable java.lang.String... 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 theApplicationContext.- Returns:
- The running
ApplicationContext
-
run
@NonNull default <T extends java.lang.AutoCloseable> T run(@NonNull java.lang.Class<T> type)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 shutdown the context.- Parameters:
type- The type of the bean to run- Returns:
- The running bean
-
-