2014-03-27 53 views
1

我正在使用JBoss 6.0.2進行eclipse。 我將一些EJB作爲Web服務公開併成功。JAXB不想使用接口

但在最後的ejb至極我要揭露,當我部署我在JBoss器件的應用,我得到這個錯誤:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions 
com.upsilon.beans.pfselection.SelectionCriterium is an interface, and JAXB can't handle interfaces. 
     this problem is related to the following location: 
       at com.upsilon.beans.pfselection.SelectionCriterium 
       at private java.util.ArrayList com.upsilon.beans.pfselection.SelectionCriteria.criteria 
       at com.upsilon.beans.pfselection.SelectionCriteria 
       at private java.util.ArrayList com.upsilon.beans.client.jaxws_asm.GetPortfolios.arg2 
       at com.upsilon.beans.client.jaxws_asm.GetPortfolios 
com.upsilon.beans.pfselection.SelectionCriterium does not have a no-arg default constructor. 
     this problem is related to the following location: 
       at com.upsilon.beans.pfselection.SelectionCriterium 
       at private java.util.ArrayList com.upsilon.beans.pfselection.SelectionCriteria.criteria 
       at com.upsilon.beans.pfselection.SelectionCriteria 
       at private java.util.ArrayList com.upsilon.beans.client.jaxws_asm.GetPortfolios.arg2 
       at com.upsilon.beans.client.jaxws_asm.GetPortfolios 

     at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106 
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:466) 
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:298) 
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:141) 
     at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1157) 
     at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:145) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51] 

這裏是我的接口:

public interface SelectionCriterium //extends Serializable 
{ 

} 

這裏是我的類SelectionCriteria

public class SelectionCriteria //implements Serializable 
{ 


    private ArrayList<SelectionCriterium> criteria = new ArrayList<SelectionCriterium>(); 

public SelectionCriteria(){} 

public SelectionCriteria(ArrayList<SelectionCriterium> criteria) 
{ 
    this.criteria = criteria; 
} 

/*public SelectionCriteria() 
{ 
    criteria = new ArrayList<SelectionCriterium>(); 
}*/ 


public ArrayList<SelectionCriterium> getCriteria() 
{ 
    return criteria; 
} 

public void setCriteria(ArrayList<SelectionCriterium> criteria) 
{ 
    this.criteria = criteria; 
} 

public void addCriterium(SelectionCriterium criterium) 
    { 
     criteria.add(criterium); 
    } 
} 

我試圖把的Xml註解,但它不工作:/

如果有人有想法?非常感謝(對不起我的英語)

+0

JAXB用於處理XML/JSON到/來自POJO編組/解組,所以很明顯你必須提供一個接口實現JAXB(沒有參數構造函數)來做這些事情。 – klimpond

回答

0

如果映射的字段/屬性是接口類型,則需要使用@XmlElement註釋來指定實現類型。

@XmlElement(type=SelectionCriteriumImpl.class) 
public ArrayList<SelectionCriterium> getCriteria() 
{ 
    return criteria; 
} 

其他信息

您可以找到有關這種使用情況在我的博客的更多信息:

+1

非常感謝,它的作品。 事實上,我的界面是空的,然後我只是創建一個SelectionCriteriumImpl實現SelectionCriterium。 我添加了註釋。 我的項目部署,也是我的網絡服務:) 非常感謝! –