本文整理匯總了Java中org.jboss.weld.environment.se.Weld類的典型用法代碼示例。如果您正苦於以下問題:Java Weld類的具體用法?Java Weld怎麽用?Java Weld使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Weld類屬於org.jboss.weld.environment.se包,在下文中一共展示了Weld類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
Weld weld = WeldInitiator.this.weld;
if (weld == null) {
// Null in case of fromTestPackage() is used
weld = createWeld().addPackage(false, description.getTestClass());
}
initWeldContainer(weld);
try {
base.evaluate();
} finally {
shutdownWeldContainer();
}
}
};
}
示例2: initWeldContainer
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
protected WeldContainer initWeldContainer(Weld weld) {
// Register mock injection services if needed
if (!resources.isEmpty()) {
weld.addServices(new MockResourceInjectionServices(resources));
}
if (ejbFactory != null) {
weld.addServices(new MockEjbInjectionServices(ejbFactory));
}
if (persistenceContextFactory != null || persistenceUnitFactory != null) {
weld.addServices(new MockJpaInjectionServices(persistenceUnitFactory, persistenceContextFactory));
}
// Init the container
container = weld.initialize();
injectInstances();
if (extension != null) {
extension.activateContexts();
}
return container;
}
示例3: testCommandDecorator
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Test
public void testCommandDecorator() {
try (WeldContainer container = new Weld()
// Disable discovery completely
.disableDiscovery()
// Add command context implementation, decorator is enabled globally/automatically
.packages(CommandContext.class)
// Add bean classes manually
.beanClasses(DummyService.class, IdService.class, TestCommand.class)
// Add command extension manually so that we don't need to create META-INF/...
.addExtension(new CommandExtension())
.initialize()) {
// Command is a bean - cotext is activated/deactivated by decorator
container.select(TestCommand.class).get().execute();
}
}
示例4: testCommandDecorator
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Test
public void testCommandDecorator() {
try (WeldContainer container = new Weld()
// Disable discovery completely
.disableDiscovery()
// Add command context implementation, decorator is enabled globally/automatically
.packages(CommandContext.class)
// Add bean classes manually
.beanClasses(DummyService.class, IdService.class, TestCommand.class)
// Add command extension manually so that we don't need to create META-INF/...
.addExtension(new CommandExtension()).initialize()) {
// Execute non-CDI bean command - context is activated/deactivated by executor
CommandExecutor executor = container.select(CommandExecutor.class).get();
executor.execute(() -> {
assertEquals(container.select(IdService.class).get().getId(), container.select(IdService.class).get().getId());
});
}
}
示例5: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
weld = new Weld().disableDiscovery().addExtension(new RouteExtension()).beanClasses(HelloHandler.class, SayHelloService.class).initialize();
vertx = Vertx.vertx();
Async async = context.async();
Router router = Router.router(vertx);
weld.select(RouteExtension.class).get().registerRoutes(router);
router.route().handler(BodyHandler.create());
vertx.createHttpServer().requestHandler(router::accept).listen(8080, (r) -> {
if (r.succeeded()) {
async.complete();
} else {
context.fail(r.cause());
}
});
}
示例6: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
vertx = Vertx.vertx();
Async async = context.async();
Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(HelloRouteObserver.class, PaymentObserverResource.class,
SayHelloService.class, PaymentService.class, RequestHelloService.class);
WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
vertx.deployVerticle(weldVerticle, deploy -> {
if (deploy.succeeded()) {
// Configure the router after Weld bootstrap finished
vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
if (listen.succeeded()) {
async.complete();
} else {
context.fail(listen.cause());
}
});
} else {
context.fail(deploy.cause());
}
});
SYNCHRONIZER.clear();
}
示例7: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
vertx = Vertx.vertx();
Async async = context.async();
Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().packages(WebRouteTest.class);
WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
vertx.deployVerticle(weldVerticle, deploy -> {
if (deploy.succeeded()) {
// Configure the router after Weld bootstrap finished
vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
if (listen.succeeded()) {
async.complete();
} else {
context.fail(listen.cause());
}
});
} else {
context.fail(deploy.cause());
}
});
SYNCHRONIZER.clear();
}
示例8: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
vertx = Vertx.vertx();
Async async = context.async();
Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(AsyncRouteObserver.class, BlockingService.class)
.packages(AsyncReference.class);
WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
vertx.deployVerticle(weldVerticle, deploy -> {
if (deploy.succeeded()) {
// Configure the router after Weld bootstrap finished
vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
if (listen.succeeded()) {
async.complete();
} else {
context.fail(listen.cause());
}
});
} else {
context.fail(deploy.cause());
}
});
SYNCHRONIZER.clear();
}
示例9: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
vertx = Vertx.vertx();
Async async = context.async();
Weld weld = WeldVerticle.createDefaultWeld().disableDiscovery().beanClasses(BlockingService.class, HelloAsyncHandler.class)
.packages(AsyncReference.class);
WeldWebVerticle weldVerticle = new WeldWebVerticle(weld);
vertx.deployVerticle(weldVerticle, deploy -> {
if (deploy.succeeded()) {
// Configure the router after Weld bootstrap finished
vertx.createHttpServer().requestHandler(weldVerticle.createRouter()::accept).listen(8080, (listen) -> {
if (listen.succeeded()) {
async.complete();
} else {
context.fail(listen.cause());
}
});
} else {
context.fail(deploy.cause());
}
});
SYNCHRONIZER.clear();
}
示例10: init
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Before
public void init(TestContext context) throws InterruptedException {
vertx = Vertx.vertx();
Async async = context.async();
final WeldWebVerticle weldVerticle = new WeldWebVerticle(createDefaultWeld().property(Weld.DEV_MODE_SYSTEM_PROPERTY, true));
vertx.deployVerticle(weldVerticle, deploy -> {
if (deploy.succeeded()) {
Router router = Router.router(vertx);
router.route().handler(BodyHandler.create());
weldVerticle.registerRoutes(router);
vertx.createHttpServer().requestHandler(router::accept).listen(8080, (listen) -> {
if (listen.succeeded()) {
async.complete();
} else {
listen.cause().printStackTrace();
}
});
} else {
deploy.cause().printStackTrace();
}
});
}
示例11: start
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
Weld weld = this.weld != null ? this.weld : createDefaultWeld();
if (weld.getContainerId() == null) {
weld.containerId(deploymentID());
}
weld.addExtension(new VertxExtension(vertx, context));
configureWeld(weld);
// Bootstrap can take some time to complete
vertx.executeBlocking(future -> {
try {
this.weldContainer = weld.initialize();
future.complete();
} catch (Exception e) {
future.fail(e);
}
}, result -> {
if (result.succeeded()) {
LOGGER.info("Weld verticle started for deployment {0}", deploymentID());
startFuture.complete();
} else {
startFuture.fail(result.cause());
}
});
}
示例12: start
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Override
public void start(Stage initStage) throws Exception {
final Stage primaryStage = new Stage(StageStyle.DECORATED);
Task<ObservableValue<Stage>> mainStageTask = new Task<ObservableValue<Stage>>() {
@Override
protected ObservableValue<Stage> call() throws Exception {
Weld weld = new Weld();
WeldContainer container = weld.initialize(); // Initialize Weld CDI
primaryStage.setTitle("StudyGuide");
primaryStage.setOnCloseRequest(event -> {
logger.debug("Closing down Weld.");
weld.shutdown();
});
primaryStage.getIcons().add(new Image(StudyGuideApplication.class.getResourceAsStream(logoResource)));
container.event().select(Stage.class, new AnnotationLiteral<StartupStage>() {
}).fire(primaryStage);
return new ReadOnlyObjectWrapper<>(primaryStage);
}
};
mainStageTask.exceptionProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
throw new IllegalStateException("Main stage loading failed.", newValue);
});
});
showSplashScreen(initStage, mainStageTask);
}
示例13: testInit
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
@Test
public void testInit() throws InterruptedException {
/**
* Some TODOs:
*
* 1. Add an extension that observes ProcessAnnotatedType, keeps in a class, and then add a getter to get the list of these that are annotated @Path
* 2. Override CDIRequestDispatcher to start a request context, and then stop when done.
*
*/
BasicConfigurator.configure();
Weld weld = new Weld();
weld.initialize();
LoadPathsExtension paths = CDI.current().select(LoadPathsExtension.class).get();
CDINettyJaxrsServer netty = new CDINettyJaxrsServer();
ResteasyDeployment rd = new ResteasyDeployment();
rd.setActualResourceClasses(paths.getResources());
rd.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
netty.setDeployment(rd);
netty.setPort(8087);
netty.setRootResourcePath("");
netty.setSecurityDomain(null);
netty.start();
Client c = ClientBuilder.newClient();
String result = c.target("http://localhost:8087").path("/").request("text/plain").accept("text/plain").get(String.class);
Assert.assertEquals("pong", result);
}
示例14: start
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
public void start() throws Exception {
logger.log(Level.INFO, "stokesdrift:server:start[status=in_progress]");
logger.log(Level.INFO, "stokesdrift:server:load_cdi_container[status=in_progress]");
weld = new Weld();
container = weld.initialize();
logger.log(Level.INFO, "stokesdrift:server:load_cdi_container[status=complete]");
applications = loadApplicationDefinitions(config);
Undertow.Builder builder = Undertow.builder().addHttpListener(config.getPort(), config.getHost());
List<DeploymentManager> managers = deployApplications(applications);
for (DeploymentManager deploymentManager : managers) {
builder.setHandler(deploymentManager.start());
}
server = builder.build();
server.start();
logger.log(Level.INFO, "stokesdrift:server:http[port="+config.getPort()+",host="+config.getHost()+"]");
logger.log(Level.INFO, "stokesdrift:server:start[status=complete]");
}
示例15: main
import org.jboss.weld.environment.se.Weld; //導入依賴的package包/類
public static void main(String[] args) {
disableLogging();
SystemAccess system = new RealSystemAccess();
new MigrationTool(new ExternalMigrationService(system),
new ToolConfig.DefaultFactory(),
system,
() -> {
/*
* Work around log4j-api message printed from missing configuration.
*/
PrintStream err = System.err;
// System.setErr(new PrintStream(new NullOutputStream()));
try {
WeldContainer container = new Weld().initialize();
return container;
} finally {
System.setErr(err);
}
}).run(args);
}