Package io.micronaut.context
Class DefaultApplicationContextBuilder
- java.lang.Object
-
- io.micronaut.context.DefaultApplicationContextBuilder
-
- All Implemented Interfaces:
ApplicationContextBuilder
,ApplicationContextConfiguration
,BeanContextConfiguration
public class DefaultApplicationContextBuilder extends java.lang.Object implements ApplicationContextBuilder, ApplicationContextConfiguration
Implementation ofApplicationContextBuilder
.- Since:
- 1.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DefaultApplicationContextBuilder()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ApplicationContextBuilder
allowEmptyProviders(boolean shouldAllow)
Whether to error on an empty bean provider.ApplicationContextBuilder
args(java.lang.String... args)
Set the command line arguments.ApplicationContextBuilder
banner(boolean isEnabled)
Whether the banner is enabled or not.ApplicationContextBuilder
bootstrapEnvironment(boolean bootstrapEnv)
Sets whether the bootstrap environment should be initialized.ApplicationContext
build()
Builds theApplicationContext
, but does not start it.ApplicationContextBuilder
classLoader(java.lang.ClassLoader classLoader)
The class loader to be used.ApplicationContextBuilder
deduceEnvironment(java.lang.Boolean deduceEnvironments)
Whether to deduce environments.ApplicationContextBuilder
defaultEnvironments(java.lang.String... environments)
The environments to use if no other environments are specified.ApplicationContextBuilder
eagerInitAnnotated(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
Specifies to eager init the given annotated types.ApplicationContextBuilder
enableDefaultPropertySources(boolean areEnabled)
Specify whether the default set of property sources should be enabled (default istrue
).ApplicationContextBuilder
environmentPropertySource(boolean environmentPropertySource)
Set whether environment variables should contribute to configuration.ApplicationContextBuilder
environments(java.lang.String... environments)
The environments to use.ApplicationContextBuilder
environmentVariableExcludes(java.lang.String... environmentVariables)
Which environment variables should not contribute to configuration.ApplicationContextBuilder
environmentVariableIncludes(java.lang.String... environmentVariables)
Which environment variables should contribute to configuration.ApplicationContextBuilder
exclude(java.lang.String... configurations)
Allow customizing the configurations that will be loaded.java.lang.ClassLoader
getClassLoader()
The class loader to use.java.util.Optional<java.lang.Boolean>
getDeduceEnvironments()
java.util.List<java.lang.String>
getDefaultEnvironments()
java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>>
getEagerInitAnnotated()
java.util.List<java.lang.String>
getEnvironments()
java.util.List<java.lang.String>
getEnvironmentVariableExcludes()
java.util.List<java.lang.String>
getEnvironmentVariableIncludes()
java.util.List<java.lang.String>
getOverrideConfigLocations()
The config locations.io.micronaut.core.io.scan.ClassPathResourceLoader
getResourceLoader()
The class path resource loader to use.ApplicationContextBuilder
include(java.lang.String... configurations)
Allow customizing the configurations that will be loaded.boolean
isAllowEmptyProviders()
boolean
isBannerEnabled()
The banner is enabled by default.java.lang.Boolean
isBootstrapEnvironmentEnabled()
boolean
isEnableDefaultPropertySources()
Whether to load the default set of property sources.boolean
isEnvironmentPropertySource()
ApplicationContextBuilder
mainClass(java.lang.Class mainClass)
The main class used by this application.protected ApplicationContext
newApplicationContext()
Creates theApplicationContext
instance.ApplicationContextBuilder
overrideConfigLocations(java.lang.String... configLocations)
Override default config locations.ApplicationContextBuilder
packages(java.lang.String... packages)
The packages to include for package scanning.ApplicationContextBuilder
properties(java.util.Map<java.lang.String,java.lang.Object> properties)
Properties to override from the environment.ApplicationContextBuilder
propertySources(PropertySource... propertySources)
Additional property sources.ApplicationContextBuilder
singletons(java.lang.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
-
-
-
-
Method Detail
-
isAllowEmptyProviders
public boolean isAllowEmptyProviders()
- Specified by:
isAllowEmptyProviders
in interfaceBeanContextConfiguration
- Returns:
- If a
NoSuchBeanException
should be thrown on a missingBeanProvider
orProvider
-
enableDefaultPropertySources
@NonNull public ApplicationContextBuilder enableDefaultPropertySources(boolean areEnabled)
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 ApplicationContextBuilder eagerInitAnnotated(java.lang.Class<? extends java.lang.annotation.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 ApplicationContextBuilder overrideConfigLocations(java.lang.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
@Nullable public java.util.List<java.lang.String> 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
@Nullable public java.lang.Boolean isBootstrapEnvironmentEnabled()
- Specified by:
isBootstrapEnvironmentEnabled
in interfaceApplicationContextConfiguration
-
getEagerInitAnnotated
public java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> getEagerInitAnnotated()
- Specified by:
getEagerInitAnnotated
in interfaceBeanContextConfiguration
- Returns:
- A set of annotated classes that should be eagerly initialized
-
singletons
@NonNull public ApplicationContextBuilder singletons(java.lang.Object... beans)
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
@NonNull public io.micronaut.core.io.scan.ClassPathResourceLoader getResourceLoader()
Description copied from interface:ApplicationContextConfiguration
The class path resource loader to use.- Specified by:
getResourceLoader
in interfaceApplicationContextConfiguration
- Returns:
- The classpath resource loader
-
getClassLoader
@NonNull public java.lang.ClassLoader getClassLoader()
Description copied from interface:BeanContextConfiguration
The class loader to use.- Specified by:
getClassLoader
in interfaceBeanContextConfiguration
- Returns:
- The class loader.
-
deduceEnvironment
@NonNull public ApplicationContextBuilder deduceEnvironment(@Nullable java.lang.Boolean deduceEnvironments)
Description copied from interface:ApplicationContextBuilder
Whether to deduce environments.- Specified by:
deduceEnvironment
in interfaceApplicationContextBuilder
- Parameters:
deduceEnvironments
- The boolean- Returns:
- This builder
-
environments
@NonNull public ApplicationContextBuilder environments(@Nullable java.lang.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 ApplicationContextBuilder defaultEnvironments(@Nullable java.lang.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
@NonNull public ApplicationContextBuilder packages(@Nullable java.lang.String... 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 ApplicationContextBuilder properties(@Nullable java.util.Map<java.lang.String,java.lang.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 ApplicationContextBuilder propertySources(@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 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 ApplicationContextBuilder environmentVariableIncludes(@Nullable java.lang.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 ApplicationContextBuilder environmentVariableExcludes(@Nullable java.lang.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
public java.util.Optional<java.lang.Boolean> getDeduceEnvironments()
- Specified by:
getDeduceEnvironments
in interfaceApplicationContextConfiguration
- Returns:
- True if the environments should be deduced
-
getEnvironments
@NonNull public java.util.List<java.lang.String> getEnvironments()
- Specified by:
getEnvironments
in interfaceApplicationContextConfiguration
- Returns:
- The environment names
-
getDefaultEnvironments
@NonNull public java.util.List<java.lang.String> 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
@Nullable public java.util.List<java.lang.String> getEnvironmentVariableIncludes()
- Specified by:
getEnvironmentVariableIncludes
in interfaceApplicationContextConfiguration
- Returns:
- The environment variables to include in configuration
-
getEnvironmentVariableExcludes
@Nullable public java.util.List<java.lang.String> getEnvironmentVariableExcludes()
- Specified by:
getEnvironmentVariableExcludes
in interfaceApplicationContextConfiguration
- Returns:
- The environment variables to exclude from configuration
-
mainClass
@NonNull public ApplicationContextBuilder mainClass(java.lang.Class 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
@NonNull public ApplicationContextBuilder classLoader(java.lang.ClassLoader 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
@NonNull public ApplicationContextBuilder args(@Nullable java.lang.String... args)
Description copied from interface:ApplicationContextBuilder
Set the command line arguments.- Specified by:
args
in interfaceApplicationContextBuilder
- Parameters:
args
- The arguments- Returns:
- This application
-
bootstrapEnvironment
@NonNull public ApplicationContextBuilder bootstrapEnvironment(boolean bootstrapEnv)
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
@NonNull public ApplicationContext 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
@NonNull protected ApplicationContext newApplicationContext()
Creates theApplicationContext
instance.- Returns:
- The application context
- Since:
- 2.0
-
include
@NonNull public ApplicationContextBuilder include(@Nullable java.lang.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 ApplicationContextBuilder exclude(@Nullable java.lang.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
@NonNull public ApplicationContextBuilder banner(boolean isEnabled)
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
@NonNull public ApplicationContextBuilder allowEmptyProviders(boolean shouldAllow)
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
-
-