@Vetoed public class Weld extends javax.enterprise.inject.se.SeContainerInitializer implements 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.
WeldContainer| Modifier and Type | Field and Description |
|---|---|
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.
|
| Modifier and Type | Method and 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) |
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(javax.enterprise.inject.spi.Extension extension)
Add an extension to the set of extensions.
|
Weld |
addExtensions(Class<? extends javax.enterprise.inject.spi.Extension>... extensionClasses) |
Weld |
addExtensions(javax.enterprise.inject.spi.Extension... 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) |
Weld |
addPackages(Class<?>... packageClasses) |
Weld |
addPackages(Package... packages) |
Weld |
addProperty(String key,
Object value) |
Weld |
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) |
Weld |
enableDevMode()
Enable the development mode.
|
Weld |
enableDiscovery() |
Weld |
enableInterceptors(Class<?>... interceptorClasses) |
Weld |
extensions(javax.enterprise.inject.spi.Extension... extensions)
Define the set of extensions.
|
String |
getContainerId() |
protected Iterable<org.jboss.weld.bootstrap.spi.Metadata<javax.enterprise.inject.spi.Extension>> |
getExtensions() |
protected <T> T |
getInstanceByType(javax.enterprise.inject.spi.BeanManager manager,
Class<T> type,
Annotation... bindings)
Utility method allowing managed instances of beans to provide entry points for non-managed beans (such as
WeldContainer). |
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 through
containerId(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) |
Weld |
selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses) |
Weld |
setBeanDiscoveryMode(org.jboss.weld.bootstrap.spi.BeanDiscoveryMode mode)
Sets the bean discovery mode for synthetic bean archive.
|
Weld |
setClassLoader(ClassLoader classLoader)
Set a
ClassLoader. |
Weld |
setProperties(Map<String,Object> propertiesMap) |
Weld |
setResourceLoader(org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
Set a
ResourceLoader 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.
|
public static final String ARCHIVE_ISOLATION_SYSTEM_PROPERTY
This key can be also used through property(String, Object).
public static final String DEV_MODE_SYSTEM_PROPERTY
This key can be also used through property(String, Object).
public static final String SHUTDOWN_HOOK_SYSTEM_PROPERTY
This key can be also used through property(String, Object).
public static final String SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTY
This key can be also used through property(String, Object).
public static final String JAVAX_ENTERPRISE_INJECT_SCAN_IMPLICIT
public static final String ALLOW_OPTIMIZED_CLEANUP
ConfigurationKey.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).
protected final Set<Class<? extends Annotation>> extendedBeanDefiningAnnotations
protected org.jboss.weld.bootstrap.spi.BeanDiscoveryMode beanDiscoveryMode
public Weld()
public Weld(String containerId)
containerId - The container identifiercontainerId(String)public Weld containerId(String containerId)
containerId - public String getContainerId()
containerId(String)public Weld beanClasses(Class<?>... classes)
classes - public Weld addBeanClass(Class<?> beanClass)
beanClass - public Weld addBeanClasses(Class<?>... classes)
addBeanClasses in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld packages(Class<?>... packageClasses)
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.
classes - public Weld addPackages(boolean scanRecursively, Class<?>... packageClasses)
addPackages in class javax.enterprise.inject.se.SeContainerInitializerscanRecursively - packageClasses - public Weld addPackages(Class<?>... packageClasses)
addPackages in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addPackages(Package... packages)
addPackages in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addPackages(boolean scanRecursively, Package... packages)
addPackages in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addPackage(boolean scanRecursively, Class<?> packageClass)
scanRecursively - packageClass - public Weld extensions(javax.enterprise.inject.spi.Extension... extensions)
extensions - public Weld addExtension(javax.enterprise.inject.spi.Extension extension)
extension - an extensionpublic Weld addExtensions(javax.enterprise.inject.spi.Extension... extensions)
addExtensions in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addExtensions(Class<? extends javax.enterprise.inject.spi.Extension>... extensionClasses)
addExtensions in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addContainerLifecycleObserver(ContainerLifecycleObserver<?> observer)
observer - ContainerLifecycleObserverpublic Weld interceptors(Class<?>... interceptorClasses)
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.
interceptorClasses - public Weld addInterceptor(Class<?> interceptorClass)
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.
interceptorClass - public Weld enableInterceptors(Class<?>... interceptorClasses)
enableInterceptors in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld decorators(Class<?>... decoratorClasses)
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.
decoratorClasses - public Weld addDecorator(Class<?> decoratorClass)
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.
decoratorClass - public Weld enableDecorators(Class<?>... decoratorClasses)
enableDecorators in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld alternatives(Class<?>... alternativeClasses)
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.
alternativeClasses - public Weld addAlternative(Class<?> alternativeClass)
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.
alternativeClass - public Weld selectAlternatives(Class<?>... alternativeClasses)
selectAlternatives in class javax.enterprise.inject.se.SeContainerInitializer@SafeVarargs public final Weld alternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
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.
alternativeStereotypeClasses - public Weld selectAlternativeStereotypes(Class<? extends Annotation>... alternativeStereotypeClasses)
selectAlternativeStereotypes in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addAlternativeStereotype(Class<? extends Annotation> alternativeStereotypeClass)
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.
alternativeStereotypeClass - public Weld property(String key, Object value)
key - value - ARCHIVE_ISOLATION_SYSTEM_PROPERTY,
SHUTDOWN_HOOK_SYSTEM_PROPERTY,
DEV_MODE_SYSTEM_PROPERTY,
ConfigurationKeypublic Weld properties(Map<String,Object> properties)
properties - public Weld addProperty(String key, Object value)
addProperty in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld setProperties(Map<String,Object> propertiesMap)
setProperties in class javax.enterprise.inject.se.SeContainerInitializerpublic Weld addServices(org.jboss.weld.bootstrap.api.Service... services)
Weld uses services to communicate with its environment, e.g. ExecutorServices or
org.jboss.weld.transaction.spi.TransactionServices.
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.
services - Servicepublic Weld setBeanDiscoveryMode(org.jboss.weld.bootstrap.spi.BeanDiscoveryMode mode)
mode - bean discovery mode in a form of an enum from BeanDiscoveryMode. Accepted values are ALL, ANNOTATEDIllegalArgumentException - if BeanDiscoveryMode.NONE is passed as an argumentpublic Weld reset()
public Weld resetAll()
reset()public Weld enableDiscovery()
disableDiscovery()public Weld disableDiscovery()
disableDiscovery in class javax.enterprise.inject.se.SeContainerInitializerpublic boolean isDiscoveryEnabled()
true if the discovery is enabled, false otherwisedisableDiscovery()public WeldContainer initialize()
containerId(String)).
The container must be shut down properly when an application is stopped. Applications are encouraged to use the try-with-resources statement or invoke
WeldContainer.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.initialize in interface ContainerInstanceFactoryinitialize in class javax.enterprise.inject.se.SeContainerInitializerenableDiscovery(),
WeldContainer.shutdown()public void shutdown()
public Weld setClassLoader(ClassLoader classLoader)
ClassLoader. The given ClassLoader will be scanned automatically for bean archives if scanning is enabled.setClassLoader in class javax.enterprise.inject.se.SeContainerInitializerclassLoader - public Weld setResourceLoader(org.jboss.weld.resources.spi.ResourceLoader resourceLoader)
ResourceLoader used to scan the application for bean archives. If you only want to use a specific ClassLoader for scanning, use
setClassLoader(ClassLoader) instead.resourceLoader - isDiscoveryEnabled()public Weld disableIsolation()
ARCHIVE_ISOLATION_SYSTEM_PROPERTYpublic Weld skipShutdownHook()
SHUTDOWN_HOOK_SYSTEM_PROPERTYpublic Weld scanClasspathEntries()
SCAN_CLASSPATH_ENTRIES_SYSTEM_PROPERTYpublic Weld enableDevMode()
DEV_MODE_SYSTEM_PROPERTYpublic Weld addBeanDefiningAnnotations(Class<? extends Annotation>... annotations)
<trim/> bean archives and/or with Weld configuration key
org.jboss.weld.bootstrap.vetoTypesWithoutBeanDefiningAnnotation, these annotations will be ignored.annotations - annotations which will be considered as Bean Defining Annotations.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();
resourceLoader - bootstrap - protected <T> T getInstanceByType(javax.enterprise.inject.spi.BeanManager manager,
Class<T> type,
Annotation... bindings)
WeldContainer). Should only called once
Weld has finished booting.manager - the BeanManager to use to access the managed instancetype - the type of the Beanbindings - the bean's qualifiersIllegalArgumentException - 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 givenjavax.enterprise.inject.UnsatisfiedResolutionException - 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 beanprotected boolean isImplicitScanEnabled()
protected boolean isSyntheticBeanArchiveRequired()
protected Iterable<org.jboss.weld.bootstrap.spi.Metadata<javax.enterprise.inject.spi.Extension>> getExtensions()
protected org.jboss.weld.bootstrap.spi.BeansXml buildSyntheticBeansXml()
protected boolean isEnabled(String key, boolean defaultValue)
Copyright © 2019. All rights reserved.