2017-07-31 60 views
1

獲取錯誤,不確定爲什麼因爲我在兩個模塊中都使用了beans.xml字符串類型Jboss6的不滿意依賴關係

WELD-001408類型不合格依賴[字符串]與限定符[@SystemProperty]在注射點[的[參數1] [構造] @注入公共com.comp.alert.EmailAlertHandler(字符串,字符串)]

SystemProperty.java:

@Qualifier 
@Retention(RetentionPolicy.RUNTIME) 
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) 
public @interface SystemProperty { 

    @Nonbinding String value(); 

} 

EmailAlertHandler.java(只包括使用@Systemproperty代碼的一部分:

在所述模塊中定義爲EmailAlertHandler

beans.xml中:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
     http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/> 

beans.xml中在所述模塊中definied爲SystemProperty:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
     http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"/> 

EmailAlertHandler這裏注入。被稱爲該sendAlertAsync方法,另一類基本上揭開序幕的功能:

@Singleton 
@Startup 
public class AlertManager { 

    @Inject @Email 
    private AlertHandler emailAlertHandler; 

    @Asynchronous 
    public void sendAlertAsync(Alert alert) { 
     // Handle alert via email 
     emailAlertHandler.sendAlert(alert); 
    } 

} 

基本上所有的解決方案,我已經在類似的不滿/丟失的依賴發現錯誤指向配置的beans.xml但是這並沒有解決任何事情。

回答

1

它看起來沒有產生這些字符串。

你有生產者嗎?

你可以嘗試使用:

public class PropertyProducer { 

    @Produces 
    public String createProperty(InjectionPoint injectionPoint) { 
     String value =injectionPoint.getAnnotation(SystemProperty.class).value(); 
     return System.getProperty(value); 
    } 
} 
相關問題