Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WELD-001408 Unsatisfied dependencies when injecting EJBs that implement interfaces

Here is the situation.

I've got the following interfaces:

public interface Parent { }
public interface ChildOne extends Parent { }
public interface ChildTwo extends Parent { }

and 2 EJBs:

@Stateless
public class FirstBean implements ChildOne { }

@Stateless
public class SecondBean implements ChildTwo { }

And also this CDI Bean:

@Named
@SessionScoped
public class TestController implements Serializable {

    @Inject
    private FirstBean firstBean;

    @Inject
    private SecondBean secondBean;
}

While trying to deploy this on Glassfish 3.1 I get the following exception:

Exception while loading the app : WELD-001408 Unsatisfied dependencies for type [FirstBean]
with qualifiers [@Default] at injection point [[field] @Inject private com.test.controllers.TestController.firstBean]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [FirstBean] 
with qualifiers [@Default] at injection point [[field] @Inject private com.test.controllers.TestController.firstBean]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:305)

When both EJBs implement the Parent interface, the exception is the same.
Also, I tried adding qualifiers, but that didn't change anything.

like image 554
jFrenetic Avatar asked Jan 27 '12 19:01

jFrenetic


2 Answers

I just played around with your construct, read a bit of the weld docu and found out the following.

You are using EJBs that implement an interface, so the no-interface view is not possible anymore (obviously), but you are trying to directly access the implementation. As soon as you declare it as an EJB you have to keep in mind the conventions. So, if you define an interface you have to use it to get access to the EJB. Changing it to the following, should work out:

@Inject
private ChildOne firstBean;

Accessing the implementation even though an interface is defined is just possible for plain CDI Managed Beans (classes without the @Stateless/@Stateful annotations). So get rid of your annotation and it will work out.

Just for your information, if you are using Glassfish. If you stick to your EJBs and try to access the parent interfaces method you will run into this bug / exception.

like image 86
Roland Tiefenbrunner Avatar answered Sep 19 '22 12:09

Roland Tiefenbrunner


Better late than never:

Annotating the SLSB aditionally with @LocalBean works for me with JBoss AS 7.1.1. I don't like the idea of creating the interface for no added value.

Using your example:

@Stateless
@LocalBean
public class FirstBean implements ChildOne { }

@Stateless
@LocalBean
public class SecondBean implements ChildTwo { }
like image 8
atamanroman Avatar answered Sep 22 '22 12:09

atamanroman