是否可以在Spring WS Web服务中重命名响应命名空间前缀?

时间:2015-02-16 10:06:09

标签: spring web-services jaxb xml-namespaces spring-ws

我根据http://spring.io/guides/gs/producing-web-service/的示例构建了一个 Spring WS webservice 。响应包含带有前缀“ns2”的命名空间。

xmlns:ns2="http://www.mycompany.com/somewhere"

皂响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns2:mitteilungResponse xmlns:ns2="http://www.mycompany.com/somewhere">
         <ns2:responseContent>
            <ns2:message>Hello World!</ns2:message>
         </ns2:responseContent>
      </ns2:mitteilungResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

是否可以将该前缀重命名为“myprefix”?怎么样?任何人

1 个答案:

答案 0 :(得分:8)

好的,我找到了解决方案。这很简单......只需将其添加到 package-info.java 中的@ XmlSchema-Annotation,如下所示:

@XmlSchema(
    xmlns = { 
        @XmlNs(prefix = "myprefix", namespaceURI="http://www.mycompany.com/foobar")
    },
    namespace = "http://www.mycompany.com/somewhere",
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package com.mycompany.project;