Springboot+CFX+WebService(Springboot通过CFX方式集成WebService)

1.导入maven依赖

<parent>
		<groupId>org.springframework.boot</groupId>   
		<artifactId>spring-boot-starter-parent</artifactId>   
		<version>2.0.3.RELEASE</version>   
		<relativePath />
	</parent>
<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-rt-frontend-jaxws</artifactId>
	<version>3.2.6</version>
</dependency>
<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-rt-transports-http</artifactId>
	<version>3.2.6</version>
</dependency>

注:Springboot-parent-2.0.3<<==>>WebService-CFX-3.2.6 暂时最高版本支持(有版本对应关系)
2.服务接口

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SO
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot 应用中使用 CFX 和 JAX-RS 规范可以方便地创建和部署 RESTful Web 服务。下面是一些使用 Spring Boot、CXF 和 JAX-RS 规范创建 RESTful Web 服务的步骤和示例代码。 1. 添加依赖项 需要在项目的 pom.xml 文件中添加以下依赖项: ``` <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxrs</artifactId> <version>3.4.0</version> </dependency> ``` 2. 创建 RESTful 资源类 创建一个类并使用 `@Path` 注解来指定资源的路径。使用 `@GET`、`@POST`、`@PUT`、`@DELETE` 等注解来指定 HTTP 方法,使用 `@Produces`、`@Consumes` 注解来指定请求和响应的数据类型。以下是一个示例代码: ``` @Path("/hello") public class HelloResource { @GET @Produces(MediaType.TEXT_PLAIN) public String sayHello() { return "Hello, World!"; } } ``` 3. 配置 RESTful Web 服务 在 Spring Boot 应用中,可以使用 `@ApplicationPath` 注解来配置 RESTful Web 服务的路径,使用 `@Bean` 注解来配置 RESTful 资源类。以下是一个示例配置: ``` @Configuration public class JaxRsConfig { @Autowired private Bus bus; @Bean public Server jaxRsServer() { JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); factory.setBus(bus); factory.setAddress("/api"); factory.setServiceBeans(Arrays.asList(new HelloResource())); return factory.create(); } } ``` 4. 启动 RESTful Web 服务 启动 Spring Boot 应用即可启动 RESTful Web 服务。访问 `http://localhost:8080/api/hello` 即可看到返回的 "Hello, World!" 字符串。 以上是使用 Spring Boot、CXF 和 JAX-RS 规范创建 RESTful Web 服务的简单示例。在实际项目中,还需要考虑数据持久化、安全性等方面的问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值