I want to make a SpringBoot Application in Java with the following Soap Web-Service:
@WebService
public class HelloWorld
{
@WebMethod
public String sayHello(String name)
{
return "Hello world, " + name;
}
}
I want to get the WSDL... I think I have to create endpoints or mapping the service? How can I do that?
Without spring-boot it works, because the file in the WEB-INF folder with the code:
<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>
and
<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>
Add spring-boot-starter-ws and org.apache.cxf cxf-bundle dependency to your project.
And create a configuration file to expose your web services. Example of such config:
@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;
}
}
To access your wsdl: http://localhost:8080/services/helloWorld?wsdl (path may be different)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.