Web Services JAX-WS与Sping Boot 的集成

r6hnlfcb  于 2022-11-15  发布在  其他
关注(0)|答案(3)|浏览(180)

我有一个既有JAX-RS又有JAX-WS的现有API。我想将它迁移到Sping Boot 应用程序中。我为JAX-RS部分所做的是注册该类:

@GET
@Path("/ping")
@Produces("text/plain")
String ping();

转换为Jersey ConfigJersey Config扩展了ResourceConfig。以下是来自同一类的JAX-WS的示例:

@WebMethod(operationName = "Ping", action = "ping-app")
String ping();

因为我已经使用了JAX-RS和JAX-WS的参考实现,所以我希望将其移植到Sping Boot 中应该很容易。我已经很容易地完成了JAX-RS集成。有没有这样简单的方法也可以集成JAX-WS?

j0pj023g

j0pj023g1#

理想情况下,你会希望使用一个Sping Boot Starter来帮助你。
启动器是一组方便的依赖项描述符,您可以将其包含在应用程序中。您可以一站式地获得所有Spring和所需的相关技术,而不必搜索示例代码并复制粘贴依赖项描述符。例如,如果您希望开始使用Spring和JPA访问数据库,只需在项目中包含spring-boot-starter-data-jpa依赖项。你就可以走了。
使用this list的官方和社区启动程序,看起来您有以下选项:

  • spring-boot-starter-jersey应该能够处理JAX-RS
  • spring-boot-web-services可能能够处理JAX-WS。据我所知,您可能需要以不同于JAX-WS的“Spring Web服务”方式来处理事情。我已经有一段时间没有使用Spring Web服务了,所以在这一点上我可能是不正确的。
  • Apache CXF starter可以同时支持JAX-RS和JAX-WS,这似乎满足了您的需求。
qq24tv8q

qq24tv8q2#

我个人没有使用过这个,但是Spring似乎为JAX-WS提供了入门包
看一下this artifact,只需要将这个依赖项添加到项目中就足够了:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
lsmepo6l

lsmepo6l3#

我已使用此依赖项解决了该问题

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
        <version>3.3.6</version>
</dependency>

并将此Bean添加到配置Bean中

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;

@Configuration
public class WebServiceConfig{

    @Autowired
    private Bus bus;

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, new SpPortImpl());
        endpoint.publish("/NpcdbService");
        return endpoint;
    }
}

SpPortImpl是用@WebService注解的类

相关问题