我想使用以下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>
答案 0 :(得分:4)
将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(路径可能不同)