Class Weld
- java.lang.Object
-
- jakarta.enterprise.inject.se.SeContainerInitializer
-
- org.jboss.weld.environment.se.Weld
-
- All Implemented Interfaces:
org.jboss.weld.environment.ContainerInstanceFactory
@Vetoed public class Weld extends SeContainerInitializer implements org.jboss.weld.environment.ContainerInstanceFactory
This builder is a preferred method of booting Weld SE container.
Typical usage looks like this:
WeldContainer container = new Weld().initialize(); container.select(Foo.class).get(); container.event().select(Bar.class).fire(new Bar()); container.shutdown();
The
WeldContainer
implements AutoCloseable:try (WeldContainer container = new Weld().initialize()) { container.select(Foo.class).get(); }
By default, the discovery is enabled so that all beans from all discovered bean archives are considered. However, it's possible to define a "synthetic" bean archive, or the set of bean classes and enablement respectively:
WeldContainer container = new Weld().beanClasses(Foo.class, Bar.class).alternatives(Bar.class).initialize()) {
Moreover, it's also possible to disable the discovery completely so that only the "synthetic" bean archive is considered:
WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class, Bar.class).initialize()) {
In the same manner, it is possible to explicitly declare interceptors, decorators, extensions and Weld-specific options (such as relaxed construction) using the builder.
Weld builder = new Weld() .disableDiscovery() .packages(Main.class, Utils.class) .interceptors(TransactionalInterceptor.class) .property("org.jboss.weld.construction.relaxed", true); WeldContainer container = builder.initialize();
The builder is reusable which means that it's possible to initialize multiple Weld containers with one builder. However, note that containers must have a unique identifier assigned when running multiple Weld instances at the same time.
- Author:
- Peter Royle, Pete Muir, Ales Justin, Martin Kouba
- See Also:
WeldContainer
-
-
Field Summary
Fields Modifier and Type Field Description static String
ADDITIONAL_BEAN_DEFINING_ANNOTATIONS_PROPERTY
By default, the set of bean-defining annotations is fixed.protected Map<Class<? extends org.jboss.weld.bootstrap.api.Service>,org.jboss.weld.bootstrap.api.Service>
additionalServices
static String
ALLOW_OPTIMIZED_CLEANUP
By default, Weld is allowed to perform efficient cleanup and further optimizations after bootstrap.static String
ARCHIVE_ISOLATION_SYSTEM_PROPERTY
By default, bean archive isolation is enabled.protected Set<Class<?>>
beanClasses
protected org.jboss.weld.bootstrap.spi.BeanDiscoveryMode
beanDiscoveryMode
static String
DEV_MODE_SYSTEM_PROPERTY
By default, the development mode is disabled.protected Set<Class<? extends Annotation>>
extendedBeanDefiningAnnotations
static String
JAVAX_ENTERPRISE_INJECT_SCAN_IMPLICIT
See also the CDI specification, section 15.1 Bean archive in Java SE.static String
SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY
By default, Weld SE does not support implicit bean archives without beans.xml.static String
SHUTDOWN_HOOK_SYSTEM_PROPERTY
By default, Weld automatically registers shutdown hook during initialization.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Weld
addAlternative(Class<?> alternativeClass)
Add an alternative class to the list of selected alternatives for a synthetic bean archive.Weld
addAlternativeStereotype(Class<? extends Annotation> alternativeStereotypeClass)
Add an alternative stereotype class to the list of selected alternative stereotypes for a synthetic bean archive.Weld
addBeanClass(Class<?> beanClass)
Add a bean class to the set of bean classes for the synthetic bean archive.Weld
addBeanClasses(Class<?>... classes)
Add provided bean classes to the synthetic bean archive.Weld
addBeanDefiningAnnotations(Class<? extends Annotation>... annotations)
Registers annotations which will be considered as bean defining annotations.Weld
addContainerLifecycleObserver(ContainerLifecycleObserver<?> observer)
Add a synthetic container lifecycle event observer.Weld
addDecorator(Class<?> decoratorClass)
Add a decorator class to the list of enabled decorators for the synthetic bean archive.Weld
addExtension(Extension extension)
Add an extension to the set of extensions.Weld
addExtensions(Extension... extensions)
Add extensions to the set of extensions.Weld
addExtensions(Class<? extends Extension>... extensionClasses)
Add extensions to the set of extensions.Weld
addInterceptor(Class<?> interceptorClass)
Add an interceptor class to the list of enabled interceptors for the synthetic bean archive.Weld
addPackage(boolean scanRecursively, Class<?> packageClass)
A package of the specified class will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.Weld
addPackages(boolean scanRecursively, Class<?>... packageClasses)
Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.Weld
addPackages(boolean scanRecursively, Package... packages)
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Weld
addPackages(Class<?>... packageClasses)
All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.Weld
addPackages(Package... packages)
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Weld
addProperty(String key, Object value)
Add a configuration property to the containerWeld
addServices(org.jboss.weld.bootstrap.api.Service... services)
Register per-deployment services which are shared across the entire application.Weld
alternatives(Class<?>... alternativeClasses)
Select alternatives for the synthetic bean archive, all previous values are removed.Weld
alternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
Select alternative stereotypes for the synthetic bean archive, all previous values are removed.Weld
beanClasses(Class<?>... classes)
Define the set of bean classes for the synthetic bean archive.protected org.jboss.weld.bootstrap.spi.BeansXml
buildSyntheticBeansXml()
Weld
containerId(String containerId)
Containers must have a unique identifier assigned when running multiple Weld instances at the same time.protected org.jboss.weld.bootstrap.spi.Deployment
createDeployment(org.jboss.weld.resources.spi.ResourceLoader resourceLoader, org.jboss.weld.bootstrap.api.CDI11Bootstrap bootstrap)
Extensions to Weld SE can subclass and override this method to customize the deployment before weld boots up.Weld
decorators(Class<?>... decoratorClasses)
Enable decorators for the synthetic bean archive, all previous values are removed.Weld
disableDiscovery()
By default, the discovery is enabled.Weld
disableIsolation()
Disable bean archive isolation, i.e.Weld
enableDecorators(Class<?>... decoratorClasses)
Add decorator classes to the list of enabled decorators for the synthetic bean archive.Weld
enableDevMode()
Enable the development mode.Weld
enableDiscovery()
Weld
enableInterceptors(Class<?>... interceptorClasses)
Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.Weld
extensions(Extension... extensions)
Define the set of extensions.String
getContainerId()
protected Iterable<org.jboss.weld.bootstrap.spi.Metadata<Extension>>
getExtensions()
protected <T> T
getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings)
Utility method allowing managed instances of beans to provide entry points for non-managed beans (such asWeldContainer
).protected Object
getPropertyValue(String key, Object defaultValue)
WeldContainer
initialize()
Bootstraps a new Weld SE container with the current container id (generated value if not set throughcontainerId(String)
).Weld
interceptors(Class<?>... interceptorClasses)
Enable interceptors for the synthetic bean archive, all previous values are removed.boolean
isDiscoveryEnabled()
protected boolean
isEnabled(String key, boolean defaultValue)
protected boolean
isImplicitScanEnabled()
protected boolean
isSyntheticBeanArchiveRequired()
Weld
packages(Class<?>... packageClasses)
All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.Weld
properties(Map<String,Object> properties)
Set all the configuration properties.Weld
property(String key, Object value)
Set the configuration property.Weld
reset()
Reset the synthetic bean archive (bean classes and enablement), explicitly added extensions and services.Weld
resetAll()
Reset all the state, except for initialized containers.Weld
scanClasspathEntries()
Scans the class path entries - implicit bean archives which don't contain a beans.xml file are supported.protected Set<String>
scanPackages()
Weld
selectAlternatives(Class<?>... alternativeClasses)
Add alternatives classes to the list of selected alternatives for the synthetic bean archive.Weld
selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.Weld
setBeanDiscoveryMode(org.jboss.weld.bootstrap.spi.BeanDiscoveryMode mode)
Sets the bean discovery mode for synthetic bean archive.Weld
setClassLoader(ClassLoader classLoader)
Set aClassLoader
.Weld
setProperties(Map<String,Object> propertiesMap)
Set all the configuration properties.Weld
setResourceLoader(org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
Set aResourceLoader
used to scan the application for bean archives.void
shutdown()
Shuts down all the containers initialized by this builder.Weld
skipShutdownHook()
Skip shutdown hook registration.-
Methods inherited from class jakarta.enterprise.inject.se.SeContainerInitializer
newInstance
-
-
-
-
Field Detail
-
ADDITIONAL_BEAN_DEFINING_ANNOTATIONS_PROPERTY
public static final String ADDITIONAL_BEAN_DEFINING_ANNOTATIONS_PROPERTY
By default, the set of bean-defining annotations is fixed. If set to aSet
of annotation classes, the set of bean-defining annotations is augmented with the contents of theSet
.This key can be used through {@link #property(String, Object}.
- See Also:
- Constant Field Values
-
ARCHIVE_ISOLATION_SYSTEM_PROPERTY
public static final String ARCHIVE_ISOLATION_SYSTEM_PROPERTY
By default, bean archive isolation is enabled. If set to false, Weld will use a "flat" deployment structure - all bean classes share the same bean archive and all beans.xml descriptors are automatically merged into one.This key can be also used through
property(String, Object)
.- See Also:
- Constant Field Values
-
DEV_MODE_SYSTEM_PROPERTY
public static final String DEV_MODE_SYSTEM_PROPERTY
By default, the development mode is disabled. If set to true, the development mode is activatedThis key can be also used through
property(String, Object)
.- See Also:
- Constant Field Values
-
SHUTDOWN_HOOK_SYSTEM_PROPERTY
public static final String SHUTDOWN_HOOK_SYSTEM_PROPERTY
By default, Weld automatically registers shutdown hook during initialization. If set to false, the registration of a shutdown hook is skipped.This key can be also used through
property(String, Object)
.- See Also:
- Constant Field Values
-
SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY
public static final String SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY
By default, Weld SE does not support implicit bean archives without beans.xml. If set to true, Weld scans the class path entries and implicit bean archives which don't contain a beans.xml file are also supported.This key can be also used through
property(String, Object)
.- See Also:
- Constant Field Values
-
JAVAX_ENTERPRISE_INJECT_SCAN_IMPLICIT
public static final String JAVAX_ENTERPRISE_INJECT_SCAN_IMPLICIT
See also the CDI specification, section 15.1 Bean archive in Java SE.- See Also:
- Constant Field Values
-
ALLOW_OPTIMIZED_CLEANUP
public static final String ALLOW_OPTIMIZED_CLEANUP
By default, Weld is allowed to perform efficient cleanup and further optimizations after bootstrap. This feature is normally controlled by integrator throughConfigurationKey.ALLOW_OPTIMIZED_CLEANUP
but in Weld SE a client of the bootstrap API is de facto in the role of integrator.This key can be also used through
property(String, Object)
.- See Also:
- Constant Field Values
-
extendedBeanDefiningAnnotations
protected final Set<Class<? extends Annotation>> extendedBeanDefiningAnnotations
-
beanDiscoveryMode
protected org.jboss.weld.bootstrap.spi.BeanDiscoveryMode beanDiscoveryMode
-
-
Constructor Detail
-
Weld
public Weld()
-
Weld
public Weld(String containerId)
- Parameters:
containerId
- The container identifier- See Also:
containerId(String)
-
-
Method Detail
-
containerId
public Weld containerId(String containerId)
Containers must have a unique identifier assigned when running multiple Weld instances at the same time.- Parameters:
containerId
-- Returns:
- self
-
getContainerId
public String getContainerId()
- Returns:
- a container identifier
- See Also:
containerId(String)
-
beanClasses
public Weld beanClasses(Class<?>... classes)
Define the set of bean classes for the synthetic bean archive.- Parameters:
classes
-- Returns:
- self
-
addBeanClass
public Weld addBeanClass(Class<?> beanClass)
Add a bean class to the set of bean classes for the synthetic bean archive.- Parameters:
beanClass
-- Returns:
- self
-
addBeanClasses
public Weld addBeanClasses(Class<?>... classes)
Description copied from class:SeContainerInitializer
Add provided bean classes to the synthetic bean archive.- Specified by:
addBeanClasses
in classSeContainerInitializer
- Parameters:
classes
- classes to add to the synthetic bean archive- Returns:
- self
-
packages
public Weld packages(Class<?>... packageClasses)
All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on bootstrap performance.
- Parameters:
classes
-- Returns:
- self
-
addPackages
public Weld addPackages(boolean scanRecursively, Class<?>... packageClasses)
Packages of the specified classes will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.- Specified by:
addPackages
in classSeContainerInitializer
- Parameters:
scanRecursively
-packageClasses
-- Returns:
- self
-
addPackages
public Weld addPackages(Class<?>... packageClasses)
Description copied from class:SeContainerInitializer
All classes from the packages of the specified classes will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Specified by:
addPackages
in classSeContainerInitializer
- Parameters:
packageClasses
- classes whose packages will be added to the synthetic bean archive- Returns:
- self
-
addPackages
public Weld addPackages(Package... packages)
Description copied from class:SeContainerInitializer
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Specified by:
addPackages
in classSeContainerInitializer
- Parameters:
packages
- packages that will be added to the synthetic bean archive- Returns:
- self
-
addPackages
public Weld addPackages(boolean scanRecursively, Package... packages)
Description copied from class:SeContainerInitializer
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.Note that the scanning possibilities are limited. Therefore, only directories and jar files from the filesystem are supported.
Scanning may also have negative impact on SE performance.
- Specified by:
addPackages
in classSeContainerInitializer
- Parameters:
scanRecursively
- should subpackages be scanned or notpackages
- packages that will be added to the synthetic bean archive- Returns:
- self
-
addPackage
public Weld addPackage(boolean scanRecursively, Class<?> packageClass)
A package of the specified class will be scanned and found classes will be added to the set of bean classes for the synthetic bean archive.- Parameters:
scanRecursively
-packageClass
-- Returns:
- self
-
extensions
public Weld extensions(Extension... extensions)
Define the set of extensions.- Parameters:
extensions
-- Returns:
- self
-
addExtension
public Weld addExtension(Extension extension)
Add an extension to the set of extensions.- Parameters:
extension
- an extension
-
addExtensions
public Weld addExtensions(Extension... extensions)
Description copied from class:SeContainerInitializer
Add extensions to the set of extensions.- Specified by:
addExtensions
in classSeContainerInitializer
- Parameters:
extensions
- extensions to use in the container- Returns:
- self
-
addExtensions
public Weld addExtensions(Class<? extends Extension>... extensionClasses)
Description copied from class:SeContainerInitializer
Add extensions to the set of extensions.- Specified by:
addExtensions
in classSeContainerInitializer
- Parameters:
extensionClasses
- extensions class to use in the container- Returns:
- self
-
addContainerLifecycleObserver
public Weld addContainerLifecycleObserver(ContainerLifecycleObserver<?> observer)
Add a synthetic container lifecycle event observer.- Parameters:
observer
-- Returns:
- self
- See Also:
ContainerLifecycleObserver
-
interceptors
public Weld interceptors(Class<?>... interceptorClasses)
Enable interceptors for the synthetic bean archive, all previous values are removed.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
interceptorClasses
-- Returns:
- self
-
addInterceptor
public Weld addInterceptor(Class<?> interceptorClass)
Add an interceptor class to the list of enabled interceptors for the synthetic bean archive.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
interceptorClass
-- Returns:
- self
-
enableInterceptors
public Weld enableInterceptors(Class<?>... interceptorClasses)
Description copied from class:SeContainerInitializer
Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Specified by:
enableInterceptors
in classSeContainerInitializer
- Parameters:
interceptorClasses
- classes of the interceptors to enable.- Returns:
- self
-
decorators
public Weld decorators(Class<?>... decoratorClasses)
Enable decorators for the synthetic bean archive, all previous values are removed.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
decoratorClasses
-- Returns:
- self
-
addDecorator
public Weld addDecorator(Class<?> decoratorClass)
Add a decorator class to the list of enabled decorators for the synthetic bean archive.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
decoratorClass
-- Returns:
- self
-
enableDecorators
public Weld enableDecorators(Class<?>... decoratorClasses)
Description copied from class:SeContainerInitializer
Add decorator classes to the list of enabled decorators for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Specified by:
enableDecorators
in classSeContainerInitializer
- Parameters:
decoratorClasses
- classes of the decorators to enable.- Returns:
- self
-
alternatives
public Weld alternatives(Class<?>... alternativeClasses)
Select alternatives for the synthetic bean archive, all previous values are removed.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
alternativeClasses
-- Returns:
- self
-
addAlternative
public Weld addAlternative(Class<?> alternativeClass)
Add an alternative class to the list of selected alternatives for a synthetic bean archive.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
alternativeClass
-- Returns:
- self
-
selectAlternatives
public Weld selectAlternatives(Class<?>... alternativeClasses)
Description copied from class:SeContainerInitializer
Add alternatives classes to the list of selected alternatives for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Specified by:
selectAlternatives
in classSeContainerInitializer
- Parameters:
alternativeClasses
- classes of the alternatives to select- Returns:
- self
-
alternativeStereotypes
@SafeVarargs public final Weld alternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
Select alternative stereotypes for the synthetic bean archive, all previous values are removed.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
alternativeStereotypeClasses
-- Returns:
- self
-
selectAlternativeStereotypes
public Weld selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
Description copied from class:SeContainerInitializer
Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.This method does not add any class to the set of bean classes of the synthetic bean archive.
- Specified by:
selectAlternativeStereotypes
in classSeContainerInitializer
- Parameters:
alternativeStereotypeClasses
- alternatives stereotypes to select- Returns:
- self
-
addAlternativeStereotype
public Weld addAlternativeStereotype(Class<? extends Annotation> alternativeStereotypeClass)
Add an alternative stereotype class to the list of selected alternative stereotypes for a synthetic bean archive.This method does not add any class to the set of bean classes for the synthetic bean archive. It's purpose is solely to compensate the absence of the
beans.xml
descriptor.- Parameters:
alternativeStereotypeClass
-- Returns:
- self
-
property
public Weld property(String key, Object value)
Set the configuration property.- Parameters:
key
-value
-- Returns:
- self
- See Also:
ARCHIVE_ISOLATION_SYSTEM_PROPERTY
,SHUTDOWN_HOOK_SYSTEM_PROPERTY
,DEV_MODE_SYSTEM_PROPERTY
,ConfigurationKey
-
properties
public Weld properties(Map<String,Object> properties)
Set all the configuration properties.- Parameters:
properties
-- Returns:
- self
-
addProperty
public Weld addProperty(String key, Object value)
Description copied from class:SeContainerInitializer
Add a configuration property to the container- Specified by:
addProperty
in classSeContainerInitializer
- Parameters:
key
- property namevalue
- property value- Returns:
- self
-
setProperties
public Weld setProperties(Map<String,Object> propertiesMap)
Description copied from class:SeContainerInitializer
Set all the configuration properties. Erase previous properties set- Specified by:
setProperties
in classSeContainerInitializer
- Parameters:
propertiesMap
- a map containing properties to add- Returns:
- self
-
addServices
public Weld addServices(org.jboss.weld.bootstrap.api.Service... services)
Register per-deployment services which are shared across the entire application.Weld uses services to communicate with its environment, e.g.
ExecutorServices
orTransactionServices
.Service implementation may specify their priority using
Priority
. Services with higher priority have precedence. Services that do not specify priority have the default priority of 4500.- Parameters:
services
-- Returns:
- self
- See Also:
Service
-
setBeanDiscoveryMode
public Weld setBeanDiscoveryMode(org.jboss.weld.bootstrap.spi.BeanDiscoveryMode mode)
Sets the bean discovery mode for synthetic bean archive. Default mode is ALL.- Parameters:
mode
- bean discovery mode in a form of an enum fromBeanDiscoveryMode
. Accepted values are ALL, ANNOTATED- Returns:
- self
- Throws:
IllegalArgumentException
- if BeanDiscoveryMode.NONE is passed as an argument
-
reset
public Weld reset()
Reset the synthetic bean archive (bean classes and enablement), explicitly added extensions and services.- Returns:
- self
-
resetAll
public Weld resetAll()
Reset all the state, except for initialized containers.- Returns:
- self
- See Also:
reset()
-
enableDiscovery
public Weld enableDiscovery()
- Returns:
- self
- See Also:
disableDiscovery()
-
disableDiscovery
public Weld disableDiscovery()
By default, the discovery is enabled. However, it's possible to disable the discovery completely so that only the "synthetic" bean archive is considered.- Specified by:
disableDiscovery
in classSeContainerInitializer
- Returns:
- self
-
isDiscoveryEnabled
public boolean isDiscoveryEnabled()
- Returns:
true
if the discovery is enabled,false
otherwise- See Also:
disableDiscovery()
-
initialize
public WeldContainer initialize()
Bootstraps a new Weld SE container with the current container id (generated value if not set throughcontainerId(String)
). The container must be shut down properly when an application is stopped. Applications are encouraged to use the try-with-resources statement or invokeWeldContainer.shutdown()
explicitly. However, a shutdown hook is also registered during initialization so that all running containers are shut down automatically when a program exits or VM is terminated. This means that it's not necessary to implement the shutdown logic in a class where a main method is used to start the container.- Specified by:
initialize
in interfaceorg.jboss.weld.environment.ContainerInstanceFactory
- Specified by:
initialize
in classSeContainerInitializer
- Returns:
- the Weld container
- See Also:
enableDiscovery()
,WeldContainer.shutdown()
-
shutdown
public void shutdown()
Shuts down all the containers initialized by this builder.
-
setClassLoader
public Weld setClassLoader(ClassLoader classLoader)
Set aClassLoader
. The givenClassLoader
will be scanned automatically for bean archives if scanning is enabled.- Specified by:
setClassLoader
in classSeContainerInitializer
- Parameters:
classLoader
-- Returns:
- self
-
setResourceLoader
public Weld setResourceLoader(org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
Set aResourceLoader
used to scan the application for bean archives. If you only want to use a specificClassLoader
for scanning, usesetClassLoader(ClassLoader)
instead.- Parameters:
resourceLoader
-- Returns:
- self
- See Also:
isDiscoveryEnabled()
-
disableIsolation
public Weld disableIsolation()
Disable bean archive isolation, i.e. use a "flat" deployment structure.- Returns:
- self
- See Also:
ARCHIVE_ISOLATION_SYSTEM_PROPERTY
-
skipShutdownHook
public Weld skipShutdownHook()
Skip shutdown hook registration.- Returns:
- self
- See Also:
SHUTDOWN_HOOK_SYSTEM_PROPERTY
-
scanClasspathEntries
public Weld scanClasspathEntries()
Scans the class path entries - implicit bean archives which don't contain a beans.xml file are supported.- Returns:
- self
- See Also:
SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY
-
enableDevMode
public Weld enableDevMode()
Enable the development mode.- Returns:
- self
- See Also:
DEV_MODE_SYSTEM_PROPERTY
-
addBeanDefiningAnnotations
public Weld addBeanDefiningAnnotations(Class<? extends Annotation>... annotations)
Registers annotations which will be considered as bean defining annotations. NOTE - If used along with<trim/>
bean archives and/or with Weld configuration keyorg.jboss.weld.bootstrap.vetoTypesWithoutBeanDefiningAnnotation
, these annotations will be ignored.- Parameters:
annotations
- annotations which will be considered as Bean Defining Annotations.- Returns:
- self
-
createDeployment
protected org.jboss.weld.bootstrap.spi.Deployment createDeployment(org.jboss.weld.resources.spi.ResourceLoader resourceLoader, org.jboss.weld.bootstrap.api.CDI11Bootstrap bootstrap)
Extensions to Weld SE can subclass and override this method to customize the deployment before weld boots up. For example, to add a custom ResourceLoader, you would subclass Weld like so:
public class MyWeld extends Weld { protected Deployment createDeployment(ResourceLoader resourceLoader, CDI11Bootstrap bootstrap) { return super.createDeployment(new MyResourceLoader(), bootstrap); } }
This could then be used as normal:
WeldContainer container = new MyWeld().initialize();
- Parameters:
resourceLoader
-bootstrap
-
-
getInstanceByType
protected <T> T getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings)
Utility method allowing managed instances of beans to provide entry points for non-managed beans (such asWeldContainer
). Should only called once Weld has finished booting.- Parameters:
manager
- the BeanManager to use to access the managed instancetype
- the type of the Beanbindings
- the bean's qualifiers- Returns:
- a managed instance of the bean
- Throws:
IllegalArgumentException
- if the given type represents a type variableIllegalArgumentException
- if two instances of the same qualifier type are givenIllegalArgumentException
- if an instance of an annotation that is not a qualifier type is givenUnsatisfiedResolutionException
- if no beans can be resolved * @throws AmbiguousResolutionException if the ambiguous dependency resolution rules failIllegalArgumentException
- if the given type is not a bean type of the given bean
-
isImplicitScanEnabled
protected boolean isImplicitScanEnabled()
-
isSyntheticBeanArchiveRequired
protected boolean isSyntheticBeanArchiveRequired()
-
buildSyntheticBeansXml
protected org.jboss.weld.bootstrap.spi.BeansXml buildSyntheticBeansXml()
-
isEnabled
protected boolean isEnabled(String key, boolean defaultValue)
-
-