Skip to content

sibay/weld-verticle-factory

Repository files navigation

Weld CDI Vert.x Verticle Factory

License

A vert.x verticle factory with dependency injection based on weld CDI. Verticles created by this factory get their dependencies injected.

Installation

Gradle

compile 'de.notizwerk:weld-verticle-factory:1.0.0'

Maven

<dependency>
    <groupId>de.notizwerk</groupId>
    <artifactId>weld-verticle-factory</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Include the jar in your classpath and deploy your verticle with the wcdi prefix. To setup the weld container correctly you must provide the packages which should be scanned for beans and cdi'ed verticles. To do that set the system property

vertx-weld-cdi-scanned-package-classes

to a comma separated list of class names (like "org.myorg.verticles.FirstVerticle, org.myorg.beans.MyBean") The packages in which the classes reside, are scanned recursively fo beans. Disable the recursion with -Dvertx-weld-cdi-recursive-scan=false

Here is a short bootstrap example:

System.setProperty(WeldVerticleFactory.SCANNED_PACKAGES_PROP,"de.notizwerk.weldcdi.examples.Bootstrap");
System.setProperty(WeldVerticleFactory.RECURSIVE_SCAN_PROP,"true"); // is true by default
Vertx vertx = Vertx.vertx();
vertx.deployVerticle("wcdi:de.notizwerk.weldcdi.examples.MapperVerticle");

The created verticles can annotate their dependencies with CDI annotations like @Inject. These properties are then injected by the factory.

public class MapperVerticle extends AbstractVerticle {
    @Inject
    private Mapper mappper;
    ...
 }

There is example code in the examples directory. You can run the example with

git clone https://github.com/sibay/weld-verticle-factory.git
cd weld-verticle-factory
./gradlew shadow
java -jar weld-verticle-factory-X.Y.Z-SNAPSHOT-all.jar

References

Author

Notizwerk

License

This project is licensed under the MIT license. See the LICENSE file for more info.

About

A vert.x verticle factory with dependency injection based on weld CDI.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages