[英]@Inject Logger (CDI) in EJB with jBoss
我試圖將我的Logger注入我的EJB中:
@Inject
Logger logger;
但我收到以下錯誤
Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between
[Producer Method [Logger] with qualifiers [@Any @Default] declared as [[method] @Produces public be.fgov.health.ecad.Resource.createLogger(InjectionPoint)],
Producer Method [Logger] with qualifiers [@Any @Default] declared as [[method] @Produces public be.fgov.health.ecad.Resource.createLogger(InjectionPoint)]]
我真的不知道這可能是什么嗎? 從我看來,下課沒有錯嗎? 我不明白為什么jBoss說存在不明確的依賴關系。
@Dependent
public class Resource {
@Produces
public Logger createLogger(final InjectionPoint ip) {
return Logger.getLogger(ip.getMember().getDeclaringClass());
}
}
您不必自己實現,此用例有一個焊接擴展:
從文檔中 :
現在,只需將記錄器對象簡單地注入到任何CDI bean中,就可以更加輕松地向應用程序中添加記錄。 只需使用@Logger限定符注釋對org.jboss.weld.log.Log類型成員進行注釋,就會將適當的logger對象注入到任何bean實例中。
import org.jboss.weld.annotation.Logger;
import org.jboss.weld.log.Log;
public class Checkout {
private @Inject @Logger Log log;
public void invoiceItems() {
ShoppingCart cart;
...
log.debug("Items invoiced for {0}", cart);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.