简体   繁体   中英

externalize namespace JAXB generated package-info.java

How to externalize the namespace value in package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "http://loclahost:9093/Request", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

in the above code how should externalize the "http://loclahost:9093/Request".

Any help is greatly appreciated

Annotation attribute values have to be compile time constants so the best you can do is to declare a public static final String NAMESPACE = "http://example.com" in another class and then say namespace = MyClass.NAMESPACE in the annotation. But you'd still have to re-compile package-info.java when MyClass changes.

The namespace specified on the the @XmlSchema annotation isn't meant to correlate to the physical location of the XML schema. It is used to qualify the element, so that your address element is different from another organizations use of an address element. This is similar to package names in Java. As with package names, people generally use domain names for this purpose. I can't think of a good reason to have the namespace look like: http://loclahost:9093/Request .

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