我希望能够直接从浏览器调用我的Web服务。通过Web浏览器从HTTPClient调用它是可以的,但如果我尝试通过浏览器直接调用它,我会收到以下错误:
SEVERE: [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Could not instantiate JAXBContext for class [class com.mycompanay.MyClass]: 8 counts of IllegalAnnotationExceptions; nested exception is com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 8 counts of IllegalAnnotationExceptions
com.mycompany.MyInterface is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
com.mycompany.myInteface
at private java.util.List com.mycompanay.MyClass.values
at com.mycompanay.myClass
@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.
this problem is related to the following location:
我试图通过@XMLElement注释引用implmentation类,但我得到了同样的错误:
public MyClass {
@XmlElement(type=MyInterfaceImpl.class, name="values")
private List<MyInterface> values;
@XmlElement(type=MyInterfaceImpl.class, name="values")
public void getValues() {
return values;
}
}
答案 0 :(得分:1)
使用@XmlElement
注释指定实现类型是正确的。问题仍然存在,因为默认情况下JAXB会将公共属性视为映射。这就是它仍在尝试处理接口的原因。由于您有注释的tr字段,因此可以将XmlAccessorType(XmlAccessType.FIELD)
添加到您的班级。
了解更多信息