i have simple case have rest service myservice
should injected bean beanb
of type beanb
implements interface beanbinterface
. error classic weld-001408 1 shown below:
org.jboss.weld.exceptions.deploymentexception: weld-001408: unsatisfied dependencies type beanbinterface qualifiers @beanbqualifier @ injection point [backedannotatedfield] @inject @beanbqualifier public com.example.myservice.beanb @ com.example.myservice.beanb(myservice.java:0)
the rest service:
import javax.ws.rs.path; import javax.inject.inject; @path("/") public class myservice { @inject @beanbqualifier(beanbqualifier.type.prod) public beanbinterface beanb; public myservice() {} }
bean interface:
public interface beanbinterface { }
bean implementation:
import javax.ejb.singleton; import javax.ejb.startup; import javax.enterprise.inject.produces; @startup @singleton @beanbqualifier(beanbqualifier.type.prod) public class beanb implements beanbinterface { private string name = "b"; public beanb() {} public string getname() {return name;} public void setname(string name) {this.name = name;} }
the bean qualifier
import javax.inject.qualifier; import java.lang.annotation.retention; import java.lang.annotation.target; import static java.lang.annotation.elementtype.field; import static java.lang.annotation.elementtype.type; import static java.lang.annotation.retentionpolicy.runtime; @qualifier @retention(runtime) @target({field, type}) public @interface beanbqualifier { type value(); enum type{prod, test} }
beans.xml (tried in meta-inf/beans.xml , tried in web-inf/beans.xml)
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="annotated"> </beans>
i tried bean-discovery-mode="all"
no luck.
if make declaration of beanb
use concrete class beanb
rather interface in myservice
works (but defeats purpose of interface):
if add @produces
factory method myservice
construct bean works defeats purpose of letting container instantiate beans me:
@javax.enterprise.inject.produces public static beanb get() { return new beanb(); }
but if @produces factory method returns interface instead won't work:
@javax.enterprise.inject.produces public static beanbinterface get() { return new beanb(); }
ejbs have weird rules interfaces exposed implemented. interfaces marked @local/@remote exposed. if want use bean interface , class need add @localbean ejb.
in short: add @local interface or @local(beanbinterface.class) beanb