1

I am using wildfly 10.1.0 and JavaEE 7

I've got this interface:

public interface TestEjb {
    String something();
}

and this Ejb class implementing it:

@LocalBean
@Stateless
public class TestEjbImpl implements TestEjb {

    @Override
    public String something() {
        return "Hello world";
    }
}

When I am injecting it to my @Path annotated jax-rs class using

@Inject
private TestEjb testEjb;

It gives an error saying "WELD-001408: Unsatisfied dependencies for type TestEjb with qualifiers @Default"

But when I inject it like

@Inject
private TestEjbImpl testEjb;

it works fine. And which is surprising both ways work with no problems in jboss-eap-6.4. But why?

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
red_white_code
  • 111
  • 2
  • 10

1 Answers1

3

First of all, you are mixing CDI injection with EJB injection. Rather use @EJB (instead of @Inject) when injecting your EJB.

@LocalBean has a no-interface view. So, you have an interface with no view annotation and a bean with a no-interface view annotation. The EJB Container understands it as a no interface view.

The best way will be to annotate the TestEjb interface with @Local view and remove the @LocalBean from the TestEjbImpl implementation in order for your solution to work.

Interface

@Local
public interface TestEjb {
    String something();
}

EJB

@Stateless
public class TestEjbImpl implements TestEjb {

    @Override
    public String something() {
        return "Hello world";
    }
}

Injection time

@EJB
private TestEjb testEjb;

I hope this helps.

Further reading...

Community
  • 1
  • 1
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • Thanks! It helped. But I would like to study this question more. And why do you think it worked fine in JBoss 6.4 and didn't in Wildfly 10? – red_white_code Nov 17 '16 at 12:49
  • Wildlfly 10 is Java EE 7 compliant. I don't know what JBoss 6.4 means. – Buhake Sindi Nov 17 '16 at 12:52
  • Yes, I did it. Thanks. What I meant by JBoss 6.4 is jboss-eap-6.4 – red_white_code Nov 17 '16 at 13:19
  • The reason why it didn't work is because, if an interface is not annotated with @Local nor the ejb bean itself, then ejb specification mandates a remote view by default. In this case, cdi container will not be able to "see" the implementation. – maress Nov 18 '16 at 07:22