简体   繁体   中英

How do I tell the JAXB marshaller to use the schemaLocation provided in my beans' package-info?

I'm trying to get my JAXB marshaller to use the provided schemaLocation without using

marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "some location");

I see that there is an option to provide a schema location in my package descriptor

@javax.xml.bind.annotation.XmlSchema(
    namespace = "http://my.website.com/TheClass"
  , elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
  , location = "http://my.website.com/TheClass TheClass.xsd"
)
package com.mypackage.beans;

but it won't print in the xml

I assume that your main issue is that the generated XML from your marshaller misses the required name space.

Have you tried adding the xmlns={@XmlNs(prefix="your_name_space", namespaceURI="http://my.website.com/TheClass")} in your XmlSchema annotation in your package descriptor?

(Suggestion taken from: JAXB namespace prefixes missing )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM