Spring Boot Soap Web服务(Java)-代码优先?

Cri*_*isV 5 java spring soap web-services spring-boot

我想使用以下Soap Web服务创建Java中的SpringBoot应用程序:

@WebService
public class HelloWorld
{
    @WebMethod
    public String sayHello(String name)
    {
        return "Hello world, " + name;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想获取WSDL ...我想必须创建端点或映射服务?我怎样才能做到这一点?

如果没有spring-boot,它会起作用,因为WEB-INF文件夹中的文件带有以下代码:

@WebService
public class HelloWorld
{
    @WebMethod
    public String sayHello(String name)
    {
        return "Hello world, " + name;
    }
}
Run Code Online (Sandbox Code Playgroud)

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint name='HelloWorld' implementation='web.service.soap.HelloWorld' url-pattern='/HelloWorld'/>
</endpoints>
Run Code Online (Sandbox Code Playgroud)

rho*_*ath 5

将spring-boot-starter-ws和org.apache.cxf cxf-bundle依赖项添加到您的项目中。

并创建一个配置文件以公开您的Web服务。这样的配置示例:

@Configuration
@EnableWs
public class WebServicesConfig {
    @Autowired
    private HelloWorld helloWorld; // your web service component

    @Bean
    public ServletRegistrationBean wsDispatcherServlet() {
        CXFServlet cxfServlet = new CXFServlet();
        return new ServletRegistrationBean(cxfServlet, "/services/*");
    }

    @Bean(name="cxf")
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public Endpoint helloWorldEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), helloWorld);
        endpoint.publish("helloWorld");
        return endpoint;
    }
}
Run Code Online (Sandbox Code Playgroud)

要访问您的wsdl:http:// localhost:8080 / services / helloWorld?wsdl(路径可能不同)