1. cxf的pom依赖
<!--webService依赖--> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.2.4</version> </dependency>
2. 服务接口
package com.pig4cloud.pigx.oms.webservice; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; /** * 进口订单WebService * * @author Fred * @date 2019-07-17 17:13:37 */ @WebService(targetNamespace = "http://webservice.oms.pigx.pig4cloud.com") public interface ImpOrderWebService { @WebMethod String hello(@WebParam(name = "name") String name); }
3. 接口实现类
package com.pig4cloud.pigx.oms.webservice.impl; import com.pig4cloud.pigx.oms.webservice.ImpOrderWebService; import org.springframework.stereotype.Component; import javax.jws.WebService; /** * 进口订单表头信息 * * @author pigx code generator * @date 2019-07-17 17:13:37 */ @WebService(serviceName = "ImpOrderWebService", // 与接口中指定的name一致 targetNamespace = "http://webservice.oms.pigx.pig4cloud.com", // 与接口中的命名空间一致,一般是接口的包名倒 endpointInterface = "com.pig4cloud.pigx.oms.webservice.ImpOrderWebService" // 接口地址 ) @Component public class ImpOrderWebServiceImpl implements ImpOrderWebService { @Override public String hello(String name) { return "hello"+name; } }
4. 服务发布配置类
package com.pig4cloud.pigx.oms.config; import com.pig4cloud.pigx.oms.webservice.ImpOrderWebService; import org.apache.cxf.Bus; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.transport.servlet.CXFServlet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.xml.ws.Endpoint; /** * 服务发布类 * * @author Fred * @date 2019-07-17 17:13:37 */ @Configuration public class WebServiceConfig { @Autowired private Bus bus; @Autowired private ImpOrderWebService impOrderWebService; @Bean public ServletRegistrationBean disServlet() { ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*"); return servletRegistrationBean; } @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(bus, impOrderWebService); endpoint.publish("/order"); return endpoint; } }
5. 项目启动后的wsdl信息
来源:https://www.cnblogs.com/fangts/p/11205324.html