CXF 快速实现基于JWS的WebService项目(转)


http://note.youdao.com/share/?id=27e232cedc05d006b1769fc437987955&type=note
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的Spring MVC项目,使用CXF框架开发Web Service的示例: 1. 创建一个Maven项目,添加以下依赖: ``` <dependencies> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.2.9.RELEASE</version> </dependency> <!-- CXF --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.4.0</version> </dependency> </dependencies> ``` 2. 创建一个接口,定义WebService的方法: ``` package com.example.webservice; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface HelloWorldService { @WebMethod String sayHello(@WebParam(name = "name") String name); } ``` 3. 创建一个实现类,实现接口中的方法: ``` package com.example.webservice; import javax.jws.WebService; @WebService(endpointInterface = "com.example.webservice.HelloWorldService") public class HelloWorldServiceImpl implements HelloWorldService { @Override public String sayHello(String name) { return "Hello " + name + "!"; } } ``` 4. 在Spring的配置文件中,添加以下配置: ``` <jaxws:endpoint id="helloWorldService" implementor="com.example.webservice.HelloWorldServiceImpl" address="/hello"/> ``` 5. 创建一个Controller类,在其中注入WebService: ``` package com.example.controller; import com.example.webservice.HelloWorldService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HelloWorldController { @Autowired private HelloWorldService helloWorldService; @RequestMapping("/hello") @ResponseBody public String sayHello(String name) { return helloWorldService.sayHello(name); } } ``` 6. 启动项目,在浏览器中访问http://localhost:8080/hello?name=world ,即可看到输出:Hello world! 这就是一个简单的Spring MVC项目,使用CXF框架开发Web Service的示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值