Spring整合CXF

1.建工程添jar包改配置,用myeclipse自带的spring插件完成构建。

     说明:先用自带的完成,然后删除jia包重新添加进去我们自己准备的jia包,目的是为了用自动生成的web.xml和applicationContext.xml。

2.修改applicationContext.xml,参考前一页PPT官网。
<?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:p="http://www.springframework.org/schema/p"
     xmlns:jaxws="http://cxf.apache.org/jaxws"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">

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

     <jaxws:endpoint id="helloworld" implementor="com.atguigu.cxf.spring.HelloWorldImpl" address="/HelloWorld"></jaxws:endpoint>

</beans>

3.修改web.xml      关键类:org.apache.cxf.transport.servlet.CXFServlet
<?xml version= "1.0" encoding ="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns= "http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id= "WebApp_ID" version ="2.5">

        <listener>
               <listener-class> org.springframework.web.context.ContextLoaderListener</listener-class >
        </listener>

        <context-param>
               <param-name> contextConfigLocation</param-name >
               <param-value> classpath:applicationContext.xml</param-value >
        </context-param>

        <servlet>
               <servlet-name> cxf01</ servlet-name>
               <servlet-class> org.apache.cxf.transport.servlet.CXFServlet</servlet-class >
        </servlet>
        <servlet-mapping>
               <servlet-name> cxf01</ servlet-name>
               <url-pattern> /services/*</url-pattern >
        </servlet-mapping>

</web-app>

4.我们的代码:
(1) 接口
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface HelloWorld
{
     @WebMethod
     @WebResult(name = "sayHelloResult")
     public String sayHello(@WebParam(name = "userName") String name,@WebParam(name = "userAge") int age);
}
(2) 实现类
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;

public class HelloWorldImpl implements HelloWorld
{
     @Override
     @WebMethod
     @WebResult(name = "sayHelloResult")
     public String sayHello(@WebParam(name = "userName") String name,@WebParam(name = "userAge") int age)
     {
          return "spring say hello to: " + name + "\t" + "age: " + age;
     }
}
5.整合:
将以上的项目部署到Tomcat中进行启动,在浏览器端输入:http://localhost:8080/cxf_spring/services 页面出现wsdl文件访问路径,点击进去,如果有wsdl报文出现,就证明部署成功。
      说明:这样做service端就可以,打成jia包直接就可以供其他人调用了。
    
       PS:若想结合源码更好的理解WebService,请:https://github.com/luomingkui/WebService
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员学习圈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值