力所能及之webservice CXF框架的应用
发布时间:2020-12-16 22:54:50 所属栏目:安全 来源:网络整理
导读:CXF框架是阿帕奇的开源webservice框架,集诸多优点于一身 工程如下: ??????????????????????????????????????????????????????????????????????????? 开发环境:myeclipse8.6? jdk1.6??? apache-cxf-2.6.16 至于jar包,最简单的方式,lib目录下的所有jar包
CXF框架是阿帕奇的开源webservice框架,集诸多优点于一身 工程如下: ??????????????????????????????????????????????????????????????????????????? 开发环境:myeclipse8.6? jdk1.6??? apache-cxf-2.6.16 至于jar包,最简单的方式,lib目录下的所有jar包,全部导进去,这里只导入如下jar文件 ????????????????????????????????????????? 写一个javabean类product,get//set方法自己写 private int id; private String name; private double price;写一下service层 public interface ProductService { public void save(Product product); public Product getProductById(int id); } public class ProductServiceImpl implements ProductService { @Override public Product getProductById(int id) { // TODO Auto-generated method stub Product product=new Product(); product.setId(101); product.setName("zhang"); product.setPrice(12.2); return product; } @Override public void save(Product product) { // TODO Auto-generated method stub System.out.println(product.getId()+" "+product.getName()+" "+product.getPrice()); } } 服务端 public class Server { public static void main(String[] args) { ServerFactoryBean bean=new ServerFactoryBean(); bean.setAddress("http://localhost:8080/hello"); bean.setServiceClass(ProductService.class); ProductService impl=new ProductServiceImpl(); bean.setServiceBean(impl); bean.create(); } } 客户端 public class Client { public static void main(String[] args) { ClientProxyFactoryBean bean=new ClientProxyFactoryBean(); bean.setAddress("http://localhost:8080/hello"); bean.setServiceClass(ProductService.class); ProductService service=(ProductService)bean.create(); System.out.println(service.getProductById(101).getName()); } }运行结果如下: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |