我完全不知所措!我有这个类:忽略CDI生产方法
package com.company.resources
import com.company.transport.Repository; //an interface for an EJB
import com.company.transport.Expression; //a simple DTO, returned by the Interface
public class ResourceProducer
{
//@EJB(lookup="foo") Repository repo;
@Produces @Named("archive")
public String getArchiveString() {
return "archive";
}
@Produces @Named("repository")
public Repository getRemoteRepository(){
//return repo;
return new Repository(){
@Override
public Expression getExpression(String s, Long aLong) {
return null;
}
};
}
}
而且,简单地把一个作品的字符串,另一种是由容器(Wildfly 9 /焊接)忽略。
在开始时,我想注入一个EJB,并且getRemoteRepository
未被注释为@Named,因为我只知道为接口Repository
提供一个生产者。获取错误,我改变了他们是相同的,以限制误差范围,甚至在注射点:
package com.company.resources
public Class ExpressionProxy {
@Inject @Named("archive") String target;
@Inject @Named("repository") Repositroy repo;
}
我得到:
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Repository with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject com.company.resources.ExpressionProxy
我没有得到这个异常为字符串!
另外,如果我注释ResourceProducer
与@ApplicationScoped
- 使其成为一个Bean - 我希望得到ambigous绑定 - 为我的制片人现在通过@Produces
注释本身发现存在于Managed Bean的。
我也只得到ambigous结合例外字符串,从不为Repository
我搬到这两个类一个的.war和同一包 - 它只是不会与Repository
工作。
我之前通过Interfaces进行了CDI注入 - 这里有什么问题?
编辑:充分披露:
我耳朵部署此,作为一个库:
app.ear/
-jaxrs.war # contains rest interface, irrelevant for this bug
-lib/
-beans.jar #contains the Producer and ExpressionProxy
-RepositoryInterface.jar # containts Repository and Expression
我想涉及的3档的每一个排列。
- 中的.war
beans
额外部署beans
作为额外的展开和耳朵/ lib目录
在/ lib目录豆提到
beans
和interfaces
作为库显然通过焊接进行扫描,因为字符串不会产生任何问题。
你能澄清这一点吗? “另外,如果我用'@ ApplicationScoped'注释ResourceProducer - 使其成为一个Bean - 我期望得到ambigous绑定 - 因为我的Producer现在通过'@ Produces'注解本身并且存在于Managed Bean中。”我在那里添加'@ ApplicationScoped'应该*不会导致模糊绑定的异常。 – jpkrohling