gpt4 book ai didi

java - 了解Spring-WS

转载 作者:行者123 更新时间:2023-12-01 23:35:22 24 4
gpt4 key购买 nike

我有一个关于 Spring 的项目,我想将其设为 SOAP Web 服务
我有实体、DAO 和 Controller ,但我宁愿不使用 Apache CXF。
我读到 Spring-WS 是契约第一。我正在使用 Intellij Idea,它从我的实体生成了 .wsdl.xsd 文件。

如果我删除我的实体并继续,它会首先算作契约(Contract)吗?
您能给我推荐一个很好的例子或者一些可以帮助我理解 Spring-WS 到底是什么以及如何开发它的东西吗?

最佳答案

啊,我最近经历了很多相同的探索,以了解如何通过基于 xsd 的 spring-ws 发布 Web 服务。我强烈建议您查看我发现的这个博客 Spring WS 2 Made Easy

在我浏览过的 20 多个内容中,它是最有帮助的之一,并且可以轻松下载完整的源代码。

您可以发布仅基于 xsd(或 wsdl)的 Web 服务。

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services
http://www.springframework.org/schema/web-services/web-services-2.0.xsd">

<!-- To detect @Endpoint -->
<sws:annotation-driven />

<!-- publish wsdl from xsd (use during development)-->
<sws:dynamic-wsdl
id="processStuff"
portTypeName="MyService"
locationUri="/myService"
requestSuffix="Request"
responseSuffix="Response"
targetNamespace="http://mycompany.com/dostuff">
<sws:xsd location="/WEB-INF/xsds/myschema.xsd"/>
</sws:dynamic-wsdl>

<!-- publish static wsdl (better for production deployments)-->
<sws:static-wsdl id="orders" location="/WEB-INF/wsdl/orders.wsdl"/>

</beans>

Spring WS 将在 id 的位置发布一个 wsdl,对于 xsd 示例,这将发布在...http://localhost:8080/[warName]/processStuff.wsdl

xsd 中与请求和响应后缀匹配的项目在发布时将被解释为 wsdl 操作。

然后,您需要开发一个用 @Endpoint 注释的类,该类与 xsd 中的操作和参数相匹配。

小例子:

@Endpoint
public class MyWebService {

@PayloadRoot(namespace = "http://mycompany.com/dostuff", localPart = "SomeRequest")
@ResponsePayload
public SomeResponse getSomething(@RequestPayload SomeRequest something) {
return new SomeResponse();
}
}

我会说这是契约(Contract)第一,你只是通过代码编写契约(Contract),我以前自己也这样做过。我宁愿亲自编写 Java 代码,也不愿编写 xsd。

正如 Sean F 所指出的,动态 wsdl 生成只能在开发期间完成,如 Spring 页面上的注释所示:

Caution

Even though it can be quite handy to create the WSDL at runtime from your XSDs, there are a couple of drawbacks to this approach. First off, though we try to keep the WSDL generation process consistent between releases, there is still the possibility that it changes (slightly). Second, the generation is a bit slow, though once generated, the WSDL is cached for later reference. It is therefore recommended to only use during the development stages of your project. Then, we recommend to use your browser to download the generated WSDL, store it in the project, and expose it with . This is the only way to be really sure that the WSDL does not change over time.

关于java - 了解Spring-WS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com