Is it possible to rename th response namespace-prefix in a Spring WS webservice?

陌路散爱 提交于 2019-12-25 02:53:58

问题


I've build a Spring WS webservice based on the example at http://spring.io/guides/gs/producing-web-service/. The response contains my namespace with the prefix "ns2".

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

Soap-Response

<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>

Is it possible to rename that prefix to "myprefix"? How? Anybody?


回答1:


OK, i found the solution. It's pretty easy... Simply add it to the @XmlSchema-Annotation in the package-info.java as follows:

@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;


来源:https://stackoverflow.com/questions/28538896/is-it-possible-to-rename-th-response-namespace-prefix-in-a-spring-ws-webservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!