2

我希望能够直接从浏览器调用我的网络服务。通过 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 注释引用实现类,但我得到了同样的错误:

public MyClass {
    @XmlElement(type=MyInterfaceImpl.class, name="values")
    private List<MyInterface> values;

    @XmlElement(type=MyInterfaceImpl.class, name="values")
    public void getValues() {
    return values;
   }
}
4

1 回答 1

1

您使用@XmlElement注释来指定实现类型是正确的。该问题仍然存在,因为默认情况下 JAXB 会将公共属性视为已映射。这就是为什么它仍在尝试处理接口的原因。由于您已注释 tr 字段,因此您可以添加XmlAccessorType(XmlAccessType.FIELD)到您的课程中。

了解更多信息

于 2013-06-05T11:33:04.750 回答