java - 实现 Spring Web 服务的更好方法

标签 java web-services spring

我发现编写 XML 配置来定义 Spring Webservice 非常困难且多余。

示例:
公开 WSDL


    <bean id="addService" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"
    p:portTypeName="add" p:locationUri="http://localhost:9080/WebServiceExample/"
    p:requestSuffix="-request" p:responseSuffix="-response">
        <property name="schema">
          <bean class="org.springframework.xml.xsd.SimpleXsdSchema" p:xsd="classpath:/WEB-INF/Addition.xsd" />
        </property>
        <property name="targetNamespace" value="addition.apps" />
    

以及 JAXB 上下文(定义编码器和解码器)


    <bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="marshaller" />
    </bean>

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="contextPath" value="apps.addition"></property>
    </bean>

    <bean id="wsTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="marshaller" />
    </bean>
    

假设我需要在一个应用程序中实现 100 个 Web 服务,那么涉及的复杂性是多少。
您能否建议我减少配置的正确方法。有任何注释驱动的方法吗?
提前致谢

最佳答案

JAX-WS和JAXB都支持注解,并且都被Spring框架支持

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/remoting.html

JAX-WS(很久以前)有一个使用 Spring 配置的引用实现

http://www.springsource.org/node/396

有关 JAX-WS 的更多信息 http://java.sun.com/developer/technicalArticles/J2SE/jax_ws_2/

Spring WS 也有自己的注释支持

http://static.springsource.org/spring-ws/site/reference/html/server.html

更多关于 Spring WS 和 JAX-WS 之间的区别

http://forum.springsource.org/showthread.php?77968-Spring-WS-vs-JAX-WS

如果您因为“契约优先”方法而喜欢 Spring WS,请看看这个

http://rphgoossens.wordpress.com/2011/02/20/developing-a-contract-first-jax-ws-webservice/

关于java - 实现 Spring Web 服务的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7329600/

相关文章:

java - 由模拟函数 Spring Boot 返回的 NPE

java - 将 DecimalFormat 与自定义模式一起使用,但没有区域设置格式

java - 如何在 Java 中调用 WSDL URL 上的 Web 服务?

java - 带有 xml 或 json 作为参数的 restful webservice

java - 测试 Spring MVC 时不断收到 404 错误

Spring编程Jdbc事务回滚不起作用

java - 无法通过持久性删除来删除 jpa 子实体

java - 将数组列表的元素复制到另一个数组列表

java - Spring MVC 中 @RequestMapping() 的正则表达式

PHP - 表单提交后未设置 $_POST 变量