Thursday, June 25, 2015

Using CDI in external JAR module

I recently had a task to create a REST API in a jar module separate from the main application. The JAR will be a dependency to the main application.
In this REST resource class I which to inject the som session scoped data about the user.

Problem is that CDI does not inspect external JAR files by default. This off cource resulted in the classic NullPointerException.

After some research  found that adding an empty beans.xml to the resources/META-INF/ tells CDI to inspect the classes in the JAR for injection points.

No comments:

Post a Comment