【问题标题】:Spring Boot Soap Web-Service (Java) - code first?Spring Boot Soap Web 服务(Java)——代码优先?
【发布时间】:2016-09-08 15:00:19
【问题描述】:

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

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

我想要获取 WSDL... 我想我必须创建端点或映射服务?我该怎么做?

没有spring-boot它可以工作,因为WEB-INF文件夹中的文件带有代码:

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

<servlet>
        <servlet-name>jaxws-servlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jaxws-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

【问题讨论】:

    标签: java spring web-services soap spring-boot


    【解决方案1】:

    将 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;
        }
    }
    

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

    【讨论】:

    • 使用这种方法,端点不是 spring 可管理的实际 bean。使用 (at)Component 或 (at)Service 注释 (at)WebService
    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2014-12-02
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多