SeContainerInitializer.newInstance().initialize()
Hammock is able to work with both JBoss Weld and Apache OpenWebBeans in Java SE mode. By using either the module ws.ament.hammock:bootstrap-weld3
or ws.ament.hammock:bootstrap-owb2
you will bring in the necessary start up components to make the main method from ws.ament.hammock.Bootstrap
work. Both implementations are based on a very simplistic bootstrap mechanism based on CDI 2.0’s SeContainer, which looks roughly like this:
SeContainerInitializer.newInstance().initialize()
Which uses default discovery, assumes that proper beans.xml
files are registered on the classpath which include registration of `@Alternative`s, `@Decorator`s etc.
Each module provides an implementation of Bootstrapper
which matches this definition:
public interface Bootstrapper {
void start();
void stop();
void configure(WebServer webServer);
}
start()
and stop()
are used in the initialization of the actual SE container as well as its shutdown. Note that stop()
is optional, in the case of Weld it will automatically shut down the container on stop. The configure()
method is specific to the web tier and is how the webserver is made aware of the CDI runtime. This is where the appropriate listeners are registered and context parameters are added.
You may be interested in writing a custom Bootstrapper. This may help control your bean discovery, enable extensions, decorators and other types of components.
SeContainerInitializer.newInstance()
.disableDiscovery()
.addPackages(true, Bootstrap.class)
.addProperty(name, value)
.initialize()
If you are trying to just write a custom initialization method, you may want to just replace the Bootstrap.main
method with your own main()
. The Bootstrappers for OWB and Weld do some amount of custom logic depending on the integration’s requirements for the WebServer
.