Cannot invoke @Remote interface in separate ear

时间:2016-02-03 02:42:28

标签: java maven java-ee jboss

This is a real newbie question but I would appreciate some help. I have looked in other questions but I haven't found a solution. Maybe I am overlooking something simple.

I am deploying an ear to jboss that has an ejb module:

  • In the ejb jar is a single bean, MyBean which is @Stateless.

  • The ejb jar also has a dependency on an api jar. In the api jar is a single @Remote interface, MyInterface.

This api jar is in the lib folder of the ejb. MyBean implements MyInterface. I deploy the ear, and this all goes ok. I am deploying it to jboss eap 6.3.0. So in theory this bean should be available to other ears & wars.

Then: I also have a war with a simple rest class to call the remote MyInterface. (The idea is just to call a remote bean from a war deployed separately from the ear that has the bean).

This gives me the following error when I deploy the war:

WELD-001408 Unsatisfied dependencies for type [MyInterface] with qualifiers [@Default] at injection point [[field] @Inject private com.test.rest.MessageRestService.myInterface]

The rest class is as follows:

package com.test.rest;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import com.test.MyInterface;

@Path("/message")
public class MessageRestService {

    @Inject
    private MyInterface myInterface;

    @GET
    @Path("/{param}")
    public Response printMessage(@PathParam("param") String msg) {
        final String result = myInterface.generateText(msg);
        return Response.status(200).entity(result).build();
    }
}

What am I doing wrong here? I have beans.xml in META-INF in both the ear and the ejb, and it is also in the war in src/main/webapp/WEB-INF/beans.xml.

I have also put bean-discovery-mode="all" in the beans.xml but no joy. Also the bean MyBean (implementing the remote interface) has a no args constructor.

Also: I have the api jar with the interface and the ejb jar brought in as dependencies in the war. But it still gives this "unsatisfied dependencies" error...

any ideas?

thanks

Update: this is the MyInterface class:

package com.test;

import javax.ejb.Local;

@Local
public interface MyInterface {

    public String generateText(String text);

}

And MyBean:

package com.mycompany;

import javax.ejb.Stateless;
import com.test.MyInterface;

@Stateless
public class MyBean implements MyInterface {

    public MyBean(){

    }

    public String generateText(String text) {
        return "Hello there! " + text;
    }

}

Bindings:

19:11:22,679 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named MyBean in deployment unit subdeployment "MavenEnterpriseApp-ejb.jar" of deployment "MavenEnterpriseApp-ear-1.0-SNAPSHOT.ear" are as follows:

    java:global/MavenEnterpriseApp-ear-1.0-SNAPSHOT/MavenEnterpriseApp-ejb/MyBean!com.test.MyInterface
    java:app/MavenEnterpriseApp-ejb/MyBean!com.test.MyInterface
    java:module/MyBean!com.test.MyInterface
    java:global/MavenEnterpriseApp-ear-1.0-SNAPSHOT/MavenEnterpriseApp-ejb/MyBean
    java:app/MavenEnterpriseApp-ejb/MyBean
    java:module/MyBean

0 个答案:

没有答案