- 官网实例地址
- 在pom.xml中添加依赖
-
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>${cxf.version}</version> </dependency>
-
- 创建接口类
-
@WebService public interface HelloWeService { @WebMethod String sayHello(@WebParam(name = "name")String name); }
-
- 创建实现类
-
@WebService @Component public class HelloWeServiceImpl implements HelloWeService { @Override public String sayHello(String name) { return "wwwww "+name; } }
-
- 创建配置类
-
@Configuration public class CXFConfig { @Autowired private Bus bus; @Autowired private HelloWeService helloWeService; @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(bus, helloWeService); endpoint.publish("/Hello"); return endpoint; } }
-
- 运行项目
- 代开浏览器访问:http://localhost:9999/services/Hello?wsdl
- 如图:
- 测试实现客户端
-
JaxWsProxyFactoryBean ws = new JaxWsProxyFactoryBean(); ws.setAddress("http://127.0.0.1:9999/services/Hello"); ws.setServiceClass(HelloWeService.class); HelloWeService helloWeService = ws.create(HelloWeService.class); System.out.println(helloWeService.sayHello("eewewewe"));
-
- 可将上图浏览器中内容另存为wdsl文件用于生成客户端代码
- 也可通过工具类实现
- java2ws
- maven插件:cxf-java2ws-plugin
Apache CXF WebService (web 服务框架) 集成到SpringBoot(2)
最新推荐文章于 2023-08-10 09:34:06 发布