0

I have the following setup:

  • EAR
    • app.war (WAR module)
      • @Inject SomeService --> works!
      • depends on ejb
    • ejb.jar (EJB module)
      • @Stateless SomeServiceBean
        • @Inject Foo --> does not work
      • beans.xml, bean-discovery-mode="all"
      • depends on tools
      • MANIFEST: Class-Path: lib/tools.jar
    • tools.jar (JAR module with CDI)
      • @ApplicationScoped FooBean
      • beans.xml, bean-discovery-mode="all"

How can I configure an ejb-module to be able to inject classes with CDI that are located in a dependent jar? Currently, CDI is throwing:

WELD-001408: Unsatisfied dependencies for type SomeService with qualifiers @Default

This exception only appears if I try to inject Foo into SomeServiceBean. Without Foo all is working fine.

Here is an excerpt from the CDI spec:

In an application deployed as an ear, the container searches every bean archive bundled with or referenced by the ear, including bean archives bundled with or referenced by wars, Jakarta Enterprise Bean jars and rars contained in the ear. The bean archives might be library jars, Jakarta Enterprise Bean jars or war WEB-INF/classes directories.

It should therefor be possible to use CDI beans referenced Jakarta Enterprise Bean (ejb-module) jars, no?

I am using Mavens EJB plugin to build the EJB module:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ejb-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
      <ejbVersion>3.2</ejbVersion>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
</plugin>

I am using Mavens EAR plugin to configure the EAR:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.2.0</version>
<configuration>
    <defaultLibBundleDir>lib/</defaultLibBundleDir>
    <modules>
        <jarModule>
            <groupId>some.group</groupId>
            <artifactId>tools</artifactId>
        </jarModule>
        <ejbModule>
            <groupId>some.group</groupId>
            <artifactId>ejb</artifactId>
            <uri>/ejb-1.0-SNAPSHOT.jar</uri>
        </ejbModule>
        <webModule>
            <groupId>some.group</groupId>
            <artifactId>app</artifactId>
            <uri>/app-1.0-SNAPSHOT.war</uri>
            <contextRoot>/app</contextRoot>
        </webModule>
    </modules>
</configuration>
</plugin>

Application server is OpenLiberty. Here is the server.xml

<server description="Cups Liberty server">

<featureManager>
    <feature>webProfile-8.0</feature>
</featureManager>

<variable name="default.http.port" defaultValue="9080"/>
<variable name="default.https.port" defaultValue="9443"/>

<httpEndpoint id="defaultHttpEndpoint"
              host="*"
              httpPort="${default.http.port}"
              httpsPort="${default.https.port}"/>

<enterpriseApplication id="open-liberty-cup-ear"
                       location="ear.ear"
                       name="open-liberty-cup-ear"/>

</server>
MaNa
  • 51
  • 6

0 Answers0