cxf2.3.3例子

开发工具:myeclipse 6.5

 

cxf 版本:2.3.3

 

server:

 

package com.cxf.server;

public interface CxfService {
    
    String sayHello(String username);
}


 

package com.cxf.server;

public class HelloWorldCxfServiceImpl implements CxfService {

    public String sayHello(String username) {
        return "Hello,"+username;
    }
}


 

package com.cxf.server;

import org.apache.cxf.frontend.ServerFactoryBean;


public class Server {
    
    public static void main(String[] args){
        HelloWorldCxfServiceImpl worldCxfServiceImpl=new HelloWorldCxfServiceImpl();
        ServerFactoryBean factoryBean=new ServerFactoryBean();
        factoryBean.setAddress("http://localhost:8080/helloword");
        factoryBean.setServiceClass(CxfService.class);
        factoryBean.setServiceBean(worldCxfServiceImpl);
        factoryBean.create();
    }
}

 

client:

 

package com.cxf.client;

public interface CxfService {
    
    String sayHello(String username);
}


 

package com.cxf.client;

import org.apache.cxf.frontend.ClientProxyFactoryBean;

import com.cxf.server.CxfService;

public class Client {
    
    public static void main(String[] args) {
        ClientProxyFactoryBean factoryBean=new ClientProxyFactoryBean();
        factoryBean.setAddress("http://localhost:8080/helloword");
        factoryBean.setServiceClass(CxfService.class);
        CxfService worldCxfService=(CxfService) factoryBean.create();
        System.out.println(worldCxfService.sayHello("张三"));
    }
}

 

低版本jdk6与cxf中的jaxb-api.jar、jaxws-api.jar会存在不兼容问题
具体异常:
java.lang.NoClassDefFoundError: javax/xml/ws/soap/MTOM–>jaxws-api.jar
java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSeeAlso–>jaxb-api.jar
因为cxf2.3.3需要jaxws-api-2.1.jar及jaxb-api-2.1.jar支持,而jdk1.6.0_02中默认的是jaxws-api-2.0.jar及jaxb-api-2.0.jar
要解决这个问题有两种处理方式:
1、升级jdk来解决,我升级到jdk1.6.0_22及以后版本是可以使用的
2、让低版本jdk也能支持jaxws-api-2.1.jar及jaxb-api-2.1.jar,那么可以如下处理:
写一个main函数,输出System.out.println(System.getProperty(“java.endorsed.dirs”)); 获得endorsed目录的位置,如果没有endorsed目录则新建,并宝贝jaxws-api-2.1.jar和jaxb-api-2.1.jar到endorsed目录下,那么jdk1.6.0_02调用的jaxws-api.jar及jaxb-api.jar也全是2.1的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值