在springmvc项目中使用webservice

1、引入maven依赖

<!-- webservice-cxf start -->
  <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- webservice-cxf end -->

2、创建webservice接口

  1. @WebService  
  2. public interface IHelloWorld {   
  3.     public String sayHello(String username);    
  4.     public void setUser(String username);   
  5. }  
3、创建实现类

  1. public class HelloWorldImpl implements IHelloWorld {  
  2.     @Override  
  3.     public String sayHello(String username) {  
  4.            
  5.         return "Hello " + username;  
  6.     }  
  7.   
  8.     @Override   
  9.     public void setUser(String username) {  
  10.            
  11.     }  
4、 在Web.xml中声明CXF监听器

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>

5、创建spring-webservice-cxf.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://cxf.apache.org/jaxws 
http://cxf.apache.org/schemas/jaxws.xsd"> 


<import resource="classpath:META-INF/cxf/cxf.xml" /> 
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 


<jaxws:endpoint id="xxxx" implementor="com.xx.xx.webservice.service.xxxx"  address="/xxxx" /> 
                                                   
<jaxws:endpoint id="xxxxxx" implementor="com.xx.webservice.xxxxxx"  address="/getEnvSalesProgress" /> 
</beans>

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您需要如下步骤来使用CXF框架开发SpringMVC项目WebService: 1. 添加CXF依赖 您需要在您的项目添加CXF相关的依赖。可以在Maven添加以下依赖: ``` <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>${cxf.version}</version> </dependency> ``` 其`${cxf.version}`是您使用的CXF版本。 2. 配置CXF 您需要在Spring配置文件配置CXF。以下是一个示例配置: ``` <bean id="helloService" class="com.example.service.HelloServiceImpl"/> <jaxws:endpoint id="helloEndpoint" implementor="#helloService" address="/hello"/> ``` 其`helloService`是您的实现类,`helloEndpoint`是您的WebService服务地址。 3. 编写WebService 您需要编写一个实现类来处理WebService请求。以下是一个示例实现类: ``` @WebService(endpointInterface = "com.example.service.HelloService") public class HelloServiceImpl implements HelloService { @Override public String sayHello(String name) { return "Hello " + name; } } ``` 其`HelloService`是您的WebService接口,`sayHello`是接口的方法。 4. 测试WebService 您可以使用SOAPUI等工具来测试您的WebService。在SOAPUI,您可以使用以下地址来访问您的WebService: ``` http://localhost:8080/hello?wsdl ``` 其`8080`是您的应用程序端口,`/hello`是您在配置文件指定的地址。 希望这些可以帮助您使用CXF框架来开发SpringMVC项目WebService

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值