public abstract class SeContainerInitializer
extends java.lang.Object
newInstance()
static method.
Typical usage looks like this:
SeContainer container = SeContainerInitializer.newInstance().initialize(); container.select(Foo.class).get(); container.close();
Since SeContainer
interface implements AutoCloseable:
try (SeContainer container = SeContainerInitializer.newInstance().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:
SeContainer container = SeContainerInitializer.newInstance().addBeanClasses(Foo.class, Bar.class).selectAlternatives(Bar.class).initialize());
Moreover, it's also possible to disable the discovery completely so that only the "synthetic" bean archive is considered:
SeContainer container = SeContainerInitializer.newInstance().disableDiscovery().addBeanClasses(Foo.class, Bar.class).initialize());
In the same manner, it is possible to explicitly declare interceptors, decorators, extensions and implementation specific options using the builder.
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance() .disableDiscovery() .addPackages(Main.class, Utils.class) .enableInterceptors(TransactionalInterceptor.class) .addProperty("property", true); SeContainer container = container.initialize();
Constructor and Description |
---|
SeContainerInitializer() |
Modifier and Type | Method and Description |
---|---|
abstract SeContainerInitializer |
addBeanClasses(java.lang.Class<?>... classes)
Add provided bean classes to the synthetic bean archive.
|
abstract SeContainerInitializer |
addExtensions(java.lang.Class<? extends Extension>... extensions)
Add extensions to the set of extensions.
|
abstract SeContainerInitializer |
addExtensions(Extension... extensions)
Add extensions to the set of extensions.
|
abstract SeContainerInitializer |
addPackages(boolean scanRecursively,
java.lang.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.*
|
abstract SeContainerInitializer |
addPackages(boolean scanRecursively,
java.lang.Package... packages)
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.
|
abstract SeContainerInitializer |
addPackages(java.lang.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.
|
abstract SeContainerInitializer |
addPackages(java.lang.Package... packages)
All classes from the specified packages will be added to the set of bean classes for the synthetic bean archive.
|
abstract SeContainerInitializer |
addProperty(java.lang.String key,
java.lang.Object value)
Add a configuration property to the container
|
abstract SeContainerInitializer |
disableDiscovery()
By default, the discovery is enabled.
|
abstract SeContainerInitializer |
enableDecorators(java.lang.Class<?>... decoratorClasses)
Add decorator classes to the list of enabled decorators for the synthetic bean archive.
|
abstract SeContainerInitializer |
enableInterceptors(java.lang.Class<?>... interceptorClasses)
Add interceptor classes to the list of enabled interceptors for the synthetic bean archive.
|
abstract SeContainer |
initialize()
Initializes a CDI SeContainerInitializer.
|
static SeContainerInitializer |
newInstance()
Returns an instance of
SeContainerInitializer
Each call returns a new instance |
abstract SeContainerInitializer |
selectAlternatives(java.lang.Class<?>... alternativeClasses)
Add alternatives classes to the list of selected alternatives for the synthetic bean archive.
|
abstract SeContainerInitializer |
selectAlternativeStereotypes(java.lang.Class<? extends java.lang.annotation.Annotation>... alternativeStereotypeClasses)
Add alternative stereotype classes to the list of selected alternative stereotypes for the synthetic bean archive.
|
abstract SeContainerInitializer |
setClassLoader(java.lang.ClassLoader classLoader)
Set a
ClassLoader . |
abstract SeContainerInitializer |
setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Set all the configuration properties.
|
public static SeContainerInitializer newInstance()
SeContainerInitializer
Each call returns a new instancejava.lang.IllegalStateException
- if called in a Jakarta EE containerpublic abstract SeContainerInitializer addBeanClasses(java.lang.Class<?>... classes)
classes
- classes to add to the synthetic bean archivepublic abstract SeContainerInitializer addPackages(java.lang.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 SE performance.
packageClasses
- classes whose packages will be added to the synthetic bean archivepublic abstract SeContainerInitializer addPackages(boolean scanRecursively, java.lang.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 SE performance.
scanRecursively
- should subpackages be scanned or notpackageClasses
- classes whose packages will be scannedpublic abstract SeContainerInitializer addPackages(java.lang.Package... packages)
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.
packages
- packages that will be added to the synthetic bean archivepublic abstract SeContainerInitializer addPackages(boolean scanRecursively, java.lang.Package... packages)
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.
scanRecursively
- should subpackages be scanned or notpackages
- packages that will be added to the synthetic bean archivepublic abstract SeContainerInitializer addExtensions(Extension... extensions)
extensions
- extensions to use in the containerpublic abstract SeContainerInitializer addExtensions(java.lang.Class<? extends Extension>... extensions)
extensions
- extensions class to use in the containerpublic abstract SeContainerInitializer enableInterceptors(java.lang.Class<?>... interceptorClasses)
This method does not add any class to the set of bean classes of the synthetic bean archive.
interceptorClasses
- classes of the interceptors to enable.public abstract SeContainerInitializer enableDecorators(java.lang.Class<?>... decoratorClasses)
This method does not add any class to the set of bean classes of the synthetic bean archive.
decoratorClasses
- classes of the decorators to enable.public abstract SeContainerInitializer selectAlternatives(java.lang.Class<?>... alternativeClasses)
This method does not add any class to the set of bean classes of the synthetic bean archive.
alternativeClasses
- classes of the alternatives to selectpublic abstract SeContainerInitializer selectAlternativeStereotypes(java.lang.Class<? extends java.lang.annotation.Annotation>... alternativeStereotypeClasses)
This method does not add any class to the set of bean classes of the synthetic bean archive.
alternativeStereotypeClasses
- alternatives stereotypes to selectpublic abstract SeContainerInitializer addProperty(java.lang.String key, java.lang.Object value)
key
- property namevalue
- property valuepublic abstract SeContainerInitializer setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
properties
- a map containing properties to addpublic abstract SeContainerInitializer disableDiscovery()
public abstract SeContainerInitializer setClassLoader(java.lang.ClassLoader classLoader)
ClassLoader
. The given ClassLoader
will be scanned automatically for bean archives if scanning is enabled.classLoader
- the class loader to usepublic abstract SeContainer initialize()
Initializes a CDI SeContainerInitializer.
Cannot be called within an application server.
SeContainer
instance associated with the container.java.lang.UnsupportedOperationException
- if called within an application server