1

I have some legacy JAX-WS @WebService annotated classes. I am trying to get this working in spring-boot. Been looking at https://jax-ws-commons.java.net/spring/ as a reference as well as http://docs.spring.io/spring/docs/current/spring-framework-reference/html/remoting.html.

My @SpringBootAnnotated class

@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());
    }
}

My XML config for the WS implementation class

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

When everything boots up, I go to localhost:8080/myws and just get back "404 Not Found: Invalid Request".

Just not sure what I am missing, its like something is not parsing those wss:binding XML declarations to tie together these servlet requests to the bean, and I am not sure how to do this in spring-boot.

This appears in logs when I first hit that mapped URI

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

thanks

bitsofinfo
  • 994
  • 3
  • 16
  • 34
  • Did you solve the problem? – Mejmo Jul 20 '15 at 15:20
  • I abandoned what I was trying to do above, and just registered a CXF servlet following this example link below. I simply could not get any of the spring documented things to work (in particular the above): https://github.com/spring-projects/spring-boot/pull/3104 – bitsofinfo Jul 21 '15 at 15:56
  • In short however, this particular issue I describe above is still not solved – bitsofinfo Jul 24 '15 at 11:17
  • Starting from Spring 4.x, the XML configuration is not recommended any more - I advice the usage of Spring´s Java Configuration. I described how to set up SpringBoot and Apache CXF in another answer already: http://stackoverflow.com/questions/21223626/apache-cxf-spring-java-config-no-xml/36137189#36137189 – jonashackt Mar 21 '16 at 17:01
  • Not sure what exactly is the problem, but I got it running with only little modification (I had to update the locations for jax-ws.dev.java.net/spring/core and jax-ws.dev.java.net/spring/servlet). Maybe there was a dependency conflict, with the JAX-WS and Spring stuff, hard to tell without the pom. Anyhow, I wrote a [tutorial on how to integrate Spring Boot and JAX-WS RI](http://herrho.com/jax-ws-webservice-with-spring-boot-and-jax-ws-ri/) – Don Ho Jan 15 '17 at 09:32

1 Answers1

-4

Your solution appears rather complex. You can get a JAX-WS service running with Spring Boot, using only

These Gradle dependencies:

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

This configuration class (Groovy):

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

@Component
class JerseyConfig extends ResourceConfig {

    JerseyConfig() {
        register(MyResource)
    }
}

This resource class:

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"]
    }
} 

and this:

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

@SpringBootApplication
class DemoJaxWSService {

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

Your endpoint will be available at localhost:8080/foo

Rune Molin
  • 66
  • 4