JAXB无法通过eclipse生成XSD时处理接口异常

时间:2017-06-30 10:12:05

标签: java eclipse jaxb jax-rs jaxb2

我正在尝试通过eclipse生成XSD / schema。

我收到下面提到的错误。

Address.class:

package blog.interfaces;


        public interface Address {

            public String getStreet();

            public void setStreet(String street);

        }

AddressImpl.class

 package blog.interfaces;

    public class AddressImpl implements Address {

        private String street;

        public String getStreet() {
            return street;
        }

        public void setStreet(String street) {
            this.street = street;
        }

    }

PhoneNumber.class

package blog.interfaces;

public interface PhoneNumber {

    String getValue();

    void setValue(String value);

}

PhoneNumberImpl.class

package blog.interfaces;

import javax.xml.bind.annotation.XmlValue;

public class PhoneNumberImpl implements PhoneNumber {

    private String value;

    @XmlValue
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}

Customer.class

package blog.interfaces;

import java.util.List;

public interface Customer {

    Address getAddress();

    void setAddress(Address address);

    List<PhoneNumber> getPhoneNumbers();

    void setPhoneNumbers(List<PhoneNumber> phoneNumbers);

}

CustomerImpl.class:

  package blog.interfaces;

    import java.util.List;

    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name="customer")
    public class CustomerImpl implements Customer {

        private Address address;
        private List<PhoneNumber> phoneNumbers;

        @XmlElement(type=AddressImpl.class)
        public Address getAddress() {
            return address;
        }

        public void setAddress(Address address) {
            this.address = address;
        }

        @XmlElement(type=PhoneNumberImpl.class, name="phone-number")
        public List<PhoneNumber> getPhoneNumbers() {
            return phoneNumbers;
        }

        public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
            this.phoneNumbers = phoneNumbers;
        }

    }

来自eclipse JAXB的错误:

!loading...!

!blog.interfaces.PhoneNumberImpl!

!blog.interfaces.Customer!

!blog.interfaces.AddressImpl!

!blog.interfaces.Address!

!blog.interfaces.CustomerImpl!

!blog.interfaces.PhoneNumber!
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
blog.interfaces.Customer is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at blog.interfaces.Customer
blog.interfaces.Address is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at blog.interfaces.Address
        at public abstract blog.interfaces.Address blog.interfaces.Customer.getAddress()
        at blog.interfaces.Customer
blog.interfaces.PhoneNumber is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at blog.interfaces.PhoneNumber
        at public abstract java.util.List blog.interfaces.Customer.getPhoneNumbers()
        at blog.interfaces.Customer

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:445)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:247)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:234)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:462)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:641)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
    at org.eclipse.jpt.jaxb.core.schemagen.Main.buildJaxbContext(Main.java:99)
    at org.eclipse.jpt.jaxb.core.schemagen.Main.generate(Main.java:78)
    at org.eclipse.jpt.jaxb.core.schemagen.Main.execute(Main.java:64)
    at org.eclipse.jpt.jaxb.core.schemagen.Main.main(Main.java:49)

!
Schema src\main\java\NewXMLSchema.xsd not created!

请帮忙

0 个答案:

没有答案