我完全不知所措!我有這個類:忽略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