在Spring Boot中,可以使用Apache CXF来从WSDL生成SOAP服务。下面是详细的步骤:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.4.5</version>
</dependency>
@WebService
public interface HelloService {
@WebMethod
String sayHello(String name);
}
@WebService
和@Service
注解:@WebService(serviceName = "HelloService")
@Service
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String name) {
return "Hello, " + name + "!";
}
}
# CXF配置
cxf.path=/soap-api
@Endpoint
和@Configuration
注解:@Endpoint
@Configuration
public class SoapServiceEndpoint {
@Autowired
private Bus bus;
@Autowired
private HelloService helloService;
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, helloService);
endpoint.publish("/hello");
return endpoint;
}
}
/soap-api/hello
路径下发布。至此,你已经成功在Spring Boot中从WSDL生成了SOAP服务。可以使用SOAP客户端工具来测试该服务。
领取专属 10元无门槛券
手把手带您无忧上云