Java 使用Spring Jaxb2Marshaller生成动态名称空间前缀
我使用SpringJava 使用Spring Jaxb2Marshaller生成动态名称空间前缀,java,spring-boot,jaxb,jaxb2,spring-oxm,Java,Spring Boot,Jaxb,Jaxb2,Spring Oxm,我使用SpringJaxb2Marshaller将java对象转换为XML,反之亦然。考虑到示例,我需要为xmlns前缀和值设置动态值 xmlns:abc="http://www.example.com" 其中前缀为abc 和值为http://www.example.com必须是可配置的(从属性文件提供) 请参阅包com.test.abc <abc:Product xmlns:abc="http://www.example.com" xmlns:xsi="http://
Jaxb2Marshaller
将java对象转换为XML,反之亦然。考虑到示例,我需要为xmlns
前缀和值设置动态值
xmlns:abc="http://www.example.com"
其中前缀
为abc
和值
为http://www.example.com
必须是可配置的(从属性文件提供)
请参阅包com.test.abc
<abc:Product
xmlns:abc="http://www.example.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<abc:productId>252</abc:productId>
<abc:productName>XYZ</abc:productName>
</abc:Product>
这里是硬编码的xmlns前缀和值。我需要提供这些服务
属性文件中的xmlns前缀和值。我怎样才能做到这一点
我使用的是SpringBoot 1.3.3
@Bean
public Jaxb2Marshaller getJaxb2Marshaller(){
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.test.abc", "com.test.xyz");
Map<String,Object> propertiesMap = new HashMap<String,Object>();
propertiesMap.put("jaxb.formatted.output", true);
marshaller.setMarshallerProperties(propertiesMap);
return marshaller;
}
@javax.xml.bind.annotation.XmlSchema(
namespace = "http://www.example.com",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
xmlns = { @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.example.com", prefix="abc")})
package com.test.abc;