当前位置: 首页 > 面试题库 >

IllegalAnnotationExceptions没有ObjectFactory带有@XmlElementDecl的元素

百里弘致
2023-03-14
问题内容

在命令提示符下运行项目时,出现以下错误

java com.javavids.jaxb.sitemap.main.Main

我收到以下错误

Exception in thread "main"    com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {unison}FromTime.
    this problem is related to the following location:
            at protected java.util.List com.javavids.jaxb.sitemap.UPM.Test.dateOrStartDateOrEndDate
            at com.javavids.jaxb.sitemap.UPM.Test
            at protected java.util.List com.javavids.jaxb.sitemap.UPM.Condition.content
            at com.javavids.jaxb.sitemap.UPM.Condition
            at protected com.javavids.jaxb.sitemap.UPM.Condition com.javavids.jaxb.sitemap.UPM.Rule.condition
            at com.javavids.jaxb.sitemap.UPM.Rule
            at protected java.util.List com.javavids.jaxb.sitemap.UPM.Policy.rule
            at com.javavids.jaxb.sitemap.UPM.Policy
            at protected java.util.List com.javavids.jaxb.sitemap.UPM.Configuration.policyOrConditionOrActionList
            at com.javavids.jaxb.sitemap.UPM.Configuration
            at protected com.javavids.jaxb.sitemap.UPM.Configuration com.javavids.jaxb.sitemap.UPM.BMWebgateConf.configuration
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
at javax.xml.bind.ContextFinder.find(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
at com.javavids.jaxb.sitemap.main.Main.main(Main.java:55)

来源:com / javavids / jaxb / sitemap / UPM / Test.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"conditionRef",
"attribute",
"op",
"dateOrStartDateOrEndDate",
"listRef",
"value"
 })
@XmlRootElement(name = "Test")

public class Test {

@XmlElement(name = "ConditionRef")
protected String conditionRef;
@XmlElement(name = "Attribute")
protected String attribute;
@XmlElement(name = "Op")
protected String op;
@XmlElementRefs({

    @XmlElementRef(name = "FromTime", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "Date", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "DurationInDays", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "EndDate", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "StartDate", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "ToTime", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "Weekday", namespace = "unison", type = JAXBElement.class, required = false),
    @XmlElementRef(name = "Frequency", namespace = "unison", type = JAXBElement.class, required = false)
})
protected List<JAXBElement<? extends Serializable>> dateOrStartDateOrEndDate;
@XmlElement(name = "ListRef")
protected String listRef;
@XmlElement(name = "Value")
protected String value;
@XmlAttribute(name = "Type", required = true)
protected String type;


 public List<JAXBElement<? extends Serializable>> getDateOrStartDateOrEndDate() {
    if (dateOrStartDateOrEndDate == null) {
        dateOrStartDateOrEndDate = new ArrayList<JAXBElement<? extends Serializable>>();
    }
    return this.dateOrStartDateOrEndDate;
}

来源:com / javavids / jaxb / sitemap / UPM / ObjectFactory.java

@XmlRegistry
public class ObjectFactory {

private final static QName _StartDate_QNAME = new QName("unison", "StartDate");    
private final static QName _Date_QNAME = new QName("unison", "Date");
private final static QName _ToTime_QNAME = new QName("unison", "ToTime");
private final static QName _CreateTime_QNAME = new QName("unison", "CreateTime");
private final static QName _EndDate_QNAME = new QName("unison", "EndDate");
private final static QName _FromTime_QNAME = new QName("unison", "FromTime");
private final static QName _DurationInDays_QNAME = new QName("unison", "DurationInDays");
private final static QName _ImportTime_QNAME = new QName("unison", "ImportTime");
private final static QName _Frequency_QNAME = new QName("unison", "Frequency");
private final static QName _Weekday_QNAME = new QName("unison", "Weekday");

@XmlElementDecl(namespace = "unison", name = "StartDate")
public JAXBElement<String> createStartDate(String value) {
    return new JAXBElement<String>(_StartDate_QNAME, String.class, null, value);
}

@XmlElementDecl(namespace = "unison", name = "FromTime")
public JAXBElement<String> createFromTime(String value) {
    return new JAXBElement<String>(_FromTime_QNAME, String.class, null, value);
}

来源:com / javavids / jaxb / sitemap / main / Main.java

public static void main(String[] args) throws JAXBException {

    File file = new File("C:\\Users\\t_pavans\\workspace\\jaxbTest1\\medialossy.xml");

    JAXBContext jaxbContext = JAXBContext.newInstance(com.javavids.jaxb.sitemap.UPM.BMWebgateConf.class);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

    //BMWebgate Root element variables
    bmw = (BMWebgateConf) jaxbUnmarshaller.unmarshal(file);

注意:该代码在我的Eclipse上完全可以正常工作。但是当我尝试在命令提示符下运行时,它会抛出异常


问题答案:

创建JAXBContextfrom类时,您需要将该ObjectFactory类包含在为创建传入的类中JAXBContext

JAXBContext jaxbContext = JAXBContext.newInstance(BMWebgateConf.class, ObjectFactory.class);

如果您的模型是从XML模式生成的,那么我建议JAXBContext在包名称上创建:

JAXBContext jaxbContext = JAXBContext.newInstance("com.javavids.jaxb.sitemap");


 类似资料:
  • 在GlassFish Server开源版本3.1中部署。1(构建12): 引起原因:java.security.PrivilegedActionExcema:com.sun.xml.bind.v2.runtime.IllegalAnnotationsExceptions: 1个IllegalAnnotationExceptions的计数没有ObjectFactory与@XmlElementDecl

  • 嗨,当我想用jaxb从java对象创建xml时,我收到了这个错误消息, javax。xml。绑定JAXBException:Provider-com。太阳xml。绑定v2。无法实例化ContextFactory:com。太阳xml。绑定v2。运行时。IllegalAnnotationsException:1 IllegalAnnotationException计数元素没有@XmlElementDe

  • 我有REST(Resteasy)客户端运行在JBoss7.1下。从服务器返回的响应要求我使用自己的JAXB ObjectFactory,因为相同的Java类型映射到多个XML元素: 我这样构建RestEasy客户端: 为什么缺省的JAXB解编组器不接收我的ObjectFactory类并使用它?我使用本地绑定的RestEasy libs(JBoss提供的RestEasy模块是过时的)。

  • 我有以下,每个都有几个元素: 我打算让变量包含、或类型的元素。我尝试将类型的元素添加到中,如下所示: 但是IDE不允许我这样做,它说: 我是否使用了?我如何解决这个问题?

  • 我想根据元素的数据集过滤元素。我创建了一个小提琴来显示我所处的位置:这里,但如你所见,当我选择“红色”时,它只是隐藏了“红色”项,而不是其他项。就像“黄色”一样,它不会做任何事情。 下面是脚本: 多谢!

  • 问题内容: 我正在尝试驱动类似于Google Maps的网络地图的一部分,在该地图上,通过鼠标悬停时的滚动来进行放大/缩小。理想情况下,我希望能够执行以下操作: 我在文档中看到的最接近的方法是和,但是这两个方法都不可以滚动。我也尝试通过Javascript将滚动条发送到页面,例如,这似乎没有任何作用。 我怎样才能做到这一点? 问题答案: 要重现/测试鼠标滚轮,您必须通过脚本注入将,和事件发送到顶部