当前位置: 首页 > 知识库问答 >
问题:

没有带有@XmlElementDecl的ObjectFactory

韦熙云
2023-03-14

在GlassFish Server开源版本3.1中部署。1(构建12):

引起原因:java.security.PrivilegedActionExcema:com.sun.xml.bind.v2.runtime.IllegalAnnotationsExceptions: 1个IllegalAnnotationExceptions的计数没有ObjectFactory与@XmlElementDecl元素{http://www.w3.org/2004/08/xop/include}包括。此问题与以下位置有关:在受保护的java.util.名单ru.gosuslugi.smev.rev120315。参考ype.contentru.gosuslugi.smev.rev120315。引用类型在公共javax.xml.bind.JAXBElementru.gosuslugi.smev.rev120315。ObjectFactory.create参考(ru.gosuslugi.smev.rev120315.引用类型)在ru.gosuslugi.smev.rev120315。对象工厂在受保护的java.util.列表ru.gosuslugi.smev.rev120315。AppDataType.anyru.gosuslugi.smev.rev120315。AppDataType在受保护ru.gosuslugi.smev.rev120315。AppDataTyperu.gosuslugi.smev.rev120315。MessageDataType.appru.gosuslugi.smev.rev120315。MessageDataType在受保护的ru. oguslugi. smev120315。MessageDataType ru. oguslugi. smev120315.基本信息类型。基本信息

来源:

src/org/w3/_2004/_08/xop/include/include。JAVA

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.08.22 at 04:13:30 PM MSK 
//


package org.w3._2004._08.xop.include;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;


/**
 * <p>Java class for Include complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="Include">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;any namespace='##other' maxOccurs="unbounded" minOccurs="0"/>
 *       &lt;/sequence>
 *       &lt;attribute name="href" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
 *       &lt;anyAttribute namespace='##other'/>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Include", propOrder = {
    "any"
})
public class Include {

    @XmlAnyElement(lax = true)
    protected List<Object> any;
    @XmlAttribute(name = "href", required = true)
    @XmlSchemaType(name = "anyURI")
    protected String href;
    @XmlAnyAttribute
    private Map<QName, String> otherAttributes = new HashMap<QName, String>();

    /**
     * Gets the value of the any property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the any property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getAny().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link Object }
     * 
     * 
     */
    public List<Object> getAny() {
        if (any == null) {
            any = new ArrayList<Object>();
        }
        return this.any;
    }

    /**
     * Gets the value of the href property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getHref() {
        return href;
    }

    /**
     * Sets the value of the href property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setHref(String value) {
        this.href = value;
    }

    /**
     * Gets a map that contains attributes that aren't bound to any typed property on this class.
     * 
     * <p>
     * the map is keyed by the name of the attribute and 
     * the value is the string value of the attribute.
     * 
     * the map returned by this method is live, and you can add new attribute
     * by updating the map directly. Because of this design, there's no setter.
     * 
     * 
     * @return
     *     always non-null
     */
    public Map<QName, String> getOtherAttributes() {
        return otherAttributes;
    }

}

org/w3/_2004/_08/xop/include/ObjectFactory。JAVA

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2012.08.22 at 04:13:30 PM MSK 
//


package org.w3._2004._08.xop.include;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;


/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the org.w3._2004._08.xop.include package. 
 * <p>An ObjectFactory allows you to programatically 
 * construct new instances of the Java representation 
 * for XML content. The Java representation of XML 
 * content can consist of schema derived interfaces 
 * and classes representing the binding of schema 
 * type definitions, element declarations and model 
 * groups.  Factory methods for each of these are 
 * provided in this class.
 * 
 */
@XmlRegistry
public class ObjectFactory {

    private final static QName _Include_QNAME = new QName("http://www.w3.org/2004/08/xop/include", "Include");

    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.w3._2004._08.xop.include
     * 
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link Include }
     * 
     */
    public Include createInclude() {
        return new Include();
    }

    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link Include }{@code >}}
     * 
     */
    @XmlElementDecl(namespace = "http://www.w3.org/2004/08/xop/include", name = "Include")
    public JAXBElement<Include> createInclude(Include value) {
        return new JAXBElement<Include>(_Include_QNAME, Include.class, null, value);
    }

}

共有3个答案

欧阳嘉
2023-03-14

您可以尝试在generate Include类上放置@XmlRoolement注释。

谷奕
2023-03-14

6个月前我遇到了完全相同的问题,老实说,我不记得它是如何解决的(可能我们不需要一些功能,所以我们把它放在一边)。但今天,我们可爱的stacktrace再次被这条信息诅咒(字面上和你的一样)

但这一次我能够应付。

包含类没有错。但不知何故,这是我的猜测,它没有为jaxb正确加载,或者在我们需要它的时候没有加载,或者...不管怎样。

我在代码中试图做的是验证肥皂消息的有效载荷。

    JAXBContext jaxbContext = JAXBContext.newInstance(UnifoTransferMsg.class) ;
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemaFactory.newSchema(new File("UnifoTransferMsg.xsd"));

    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setSchema(schema);
    marshaller.marshal(inputmsg, System.out);

让我来看看硬编码的值,这只是为了调试。尽管如此,第一行是抛出异常的地方,因为Jaxb不知何故对Include一无所知,或者使用了错误的类。要修复它,需要在同一个调用中加载多个类。

所以对我来说最终的解决办法

JAXBContext.newInstance(Include.class, UnifoTransferMsg.class);

希望这对我有所帮助,也许有一天我会进一步阐述问题的真正原因。

舒飞捷
2023-03-14

当从XML模式生成JAXB模型时,我总是建议使用生成模型的包名创建JAXBContext

JAXBContext jc = JAXBContext.newInstance("org.w3._2004._08.xop.include");

您没有指定要部署到Glassfish的应用程序类型,但是如果它是JAX-RS/泽西应用程序,我建议使用ContextResolver。这是一种标准机制,它使您能够更好地控制如何创建JAXBContext。下面是一个例子。

import java.util.*;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextFactory;

@Provider
@Produces({"application/xml", "application/json"})
public class SampleContextResolver implements ContextResolver<JAXBContext> {

    private JAXBContext jc;

    public SampleContextResolver() {
        try {
            jc = JAXBContext.newInstance("org.w3._2004._08.xop.include");
        } catch(JAXBException e) {
            throw new RuntimeException(e);
        }
    }

    public JAXBContext getContext(Class<?> clazz) {
        if(clazz.getPackage().getName().equals("org.w3._2004._08.xop.include")) {
            return jc;
        }
        return null;
    }

}
 类似资料:
  • 问题内容: 在命令提示符下运行项目时,出现以下错误 我收到以下错误 来源:com / javavids / jaxb / sitemap / UPM / Test.java 来源:com / javavids / jaxb / sitemap / UPM / ObjectFactory.java 来源:com / javavids / jaxb / sitemap / main / Main.ja

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

  • 在使用MapStruct、Lombock和Spring时,我在Tomcat 9中的应用程序部署中遇到以下错误: 我的spring配置类在包层次结构的根目录中设置包扫描。映射器的实现也是在target/generated-sources下生成的: 我的错误表明Spring找不到实现类,我遗漏了什么?我试图将generated-sources文件夹添加到构建路径并将其包含在包扫描中,但没有成功。

  • 我有一个基于网站的网络应用程序,通过AAD登录验证用户。成功的登录会将用户重定向回带有访问令牌的应用程序(这部分都是使用adal_angular.js/adal.js完成的) 然后将令牌传递给一个基于站点的api,该api代表用户获得一个新的令牌来调用下游api,如本例(https://github.com/azure-samples/active-directory-dotnet-webapi-

  • 我正在运行一个Ruby on Rails应用程序,Webpacker使用Yarn,并试图通过Docker Compose在Docker上运行这个程序。当我运行docker compose build时,它看起来运行成功,但找不到node\u modules文件夹,我无法使用任何节点包。我试着像其他帖子中建议的那样,将

  • 我试图用saml修改spring boot安全性的一个示例程序。https://github.com/vdenotaris/spring-boot-security-saml-sample.我从身份提供者那里获得了证书(.crt),并尝试创建一个示例密钥库(.jks),以在集成到应用程序之前测试我的连接性。我按照以下步骤创建证书。 创建密钥存储 当我试图列出我的密钥库时,我有一个私钥 列出密钥库