【问题标题】:Getting JAX-WS WebServices working in Spring Boot让 JAX-WS WebServices 在 Spring Boot 中工作
【发布时间】:2015-10-04 14:53:02
【问题描述】:

我有一些遗留的 JAX-WS @WebService 注释类。我正试图让它在 spring-boot 中工作。一直在看https://jax-ws-commons.java.net/spring/ 作为参考以及http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html

我的@SpringBootAnnotated 类

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class SpringBootBooter extends SpringBootServletInitializer {

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        ServletRegistrationBean reg = new ServletRegistrationBean(new WSSpringServlet(),"/myws");
        reg.setLoadOnStartup(1);
        return reg;
    }

    public static void main(String args[]) throws Exception {
        SpringApplication.run(new Object[] {
            SpringBootBooter.class,
            new ClassPathResource("myLegacyAppContextWithWSBean.xml")
        }, args);
    }

    @Override
    public void onStartup(final ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        servletContext.addListener(new WSServletContextListener());
    }
}

我的 WS 实现类的 XML 配置

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:ws="http://jax-ws.dev.java.net/spring/core"
  xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://jax-ws.dev.java.net/spring/core
    http://jax-ws.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    http://jax-ws.java.net/spring/servlet.xsd">

  <wss:binding url="/myws">
    <wss:service>
      <ws:service bean="#mywsbean" />
    </wss:service>
  </wss:binding>

  <bean id="mywsbean" class="com.items.MyWsBean">
  </bean>

</beans>

当一切启动后,我去 localhost:8080/myws 并返回“404 Not Found: Invalid Request”。

只是不确定我缺少什么,就像没有解析那些 wss:binding XML 声明以将这些 servlet 请求与 bean 绑定在一起,我不知道如何在 spring-boot 中执行此操作。

当我第一次点击映射的 URI 时,这会出现在日志中

Jul 15, 2015 9:40:18 AM com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
INFO: WSSERVLET14: JAX-WS servlet initializing

谢谢

【问题讨论】:

  • 问题解决了吗?
  • 我放弃了我在上面尝试做的事情,只是按照下面的示例链接注册了一个 CXF servlet。我根本无法让任何 spring 记录的东西起作用(特别是上面的):github.com/spring-projects/spring-boot/pull/3104
  • 总之,我上面描述的这个特殊问题仍然没有解决
  • 从 Spring 4.x 开始,不再推荐 XML 配置 - 我建议使用 Spring 的 Java 配置。我已经在另一个答案中描述了如何设置 SpringBoot 和 Apache CXF:stackoverflow.com/questions/21223626/…
  • 不确定到底是什么问题,但我只做了很少的修改就让它运行了(我必须更新 jax-ws.dev.java.net/spring/core 和 jax-ws 的位置.dev.java.net/spring/servlet)。也许有一个依赖冲突,与 JAX-WS 和 Spring 的东西,如果没有 pom.反正我写了tutorial on how to integrate Spring Boot and JAX-WS RI

标签: spring-boot jax-ws


【解决方案1】:

您的解决方案看起来相当复杂。您可以使用 Spring Boot 获得 JAX-WS 服务,仅使用

这些 Gradle 依赖项:

dependencies {
  compile "org.springframework.boot:spring-boot-starter-actuator"
  compile "org.springframework.boot:spring-boot-starter-web"
  compile "org.springframework.boot:spring-boot-starter-jersey"
}

这个配置类(Groovy):

import org.glassfish.jersey.server.ResourceConfig
import org.springframework.stereotype.Component

@Component
class JerseyConfig extends ResourceConfig {

    JerseyConfig() {
        register(MyResource)
    }
}

这个资源类:

import org.springframework.stereotype.Component
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.Context
import javax.ws.rs.core.MediaType

@Component
@Path("/foo")
class MyResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Map bar() {
      return ["hello":"world"]
    }
} 

还有这个:

import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication

@SpringBootApplication
class DemoJaxWSService {

  static void main(String[] args) {
    SpringApplication.run DemoJaxWSService, args
  }
}

您的端点将在localhost:8080/foo 可用

【讨论】:

  • 我正在尝试采用遗留的 JAX-WS (soap) 注释类并在 Spring Boot 中运行它们。您的示例显示的是 REST 服务。
  • 哦,对不起!我的错误
猜你喜欢
  • 2019-01-10
  • 2017-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-16
  • 1970-01-01
  • 2011-02-22
相关资源
最近更新 更多