org.sdase.commons.server.weld.DropwizardWeldHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sda-commons-server-weld Show documentation
Show all versions of sda-commons-server-weld Show documentation
A libraries to bootstrap services easily that follow the patterns and specifications promoted by the SDA SE
package org.sdase.commons.server.weld;
import io.dropwizard.core.Application;
import org.jboss.weld.environment.se.WeldContainer;
import org.sdase.commons.server.weld.internal.WeldSupport;
/**
* Start a Dropwizard application with Weld support.
*
* This is used to create the Application class inside the Weld Context, so that the Application,
* or instances produced by the Application, can be injected.
*
*
Example usage:
*
*
* public static void main(final String[] args) throws Exception {
* DropwizardWeldHelper.run(Application.class, args);
* }
*
*/
public class DropwizardWeldHelper {
// We are rethrowing a generic exception that we have no control over, ignore the warning
public static > void run(Class applicationClass, String... arguments)
throws Exception { // NOSONAR
WeldSupport.initializeCDIProviderIfRequired();
// We are not calling shutdown on the weld container, as it has an automatic shutdown hook on
// application exit,
// so ignore the warning. Calling shutdown here is dangerous, as Application.run isn't blocking
// as one would
// expect and that would cause the weld container to be unloaded directly after startup while
// the application is
// still running.
WeldContainer weldContainer = WeldSupport.createWeldContainer(); // NOSONAR
weldContainer.select(applicationClass).getHandle().get().run(arguments);
}
private DropwizardWeldHelper() {
// No public constructor
}
}