cxf发布rest风格的webService
来源:互联网 发布:制作淘宝无缝拼接主图 编辑:程序博客网 时间:2024/06/05 04:50
- 第一步,创建工程并导入cxf jar包。
- 第二步,编写pojo。
package com.scut.pojo;import java.util.Date;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;import javax.xml.bind.annotation.XmlTransient;@XmlRootElement(name="student")public class Student { @XmlElement public int id; @XmlElement public String name; @XmlElement public Date birthday; @XmlTransient public int getId() { return id; } public void setId(int id) { this.id = id; } @XmlTransient public String getName() { return name; } public void setName(String name) { this.name = name; } @XmlTransient public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; }}
- 第三步,编写SEI和实现类
package com.scut.dao;import java.util.List;import javax.jws.WebService;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;import com.scut.pojo.Student;@WebService@Path("/student")public interface StudentService { @Path("/query/{id}") @GET @Produces(MediaType.APPLICATION_XML) public Student queryStudent(@PathParam("id") int id); @GET @Path("/querylist/{type}") @Produces(MediaType.APPLICATION_JSON) public List<Student> queryStudentList(@PathParam("type") String type);}
package com.scut.dao.impl;import java.util.ArrayList;import java.util.Date;import java.util.List;import com.scut.dao.StudentService;import com.scut.pojo.Student;public class StudentServiceImpl implements StudentService{ public Student queryStudent(int id) { Student s=new Student(); s.setBirthday(new Date()); s.setId(001); s.setName("yj"); return s; } public List<Student> queryStudentList(String type) { List<Student>list=new ArrayList<Student>(); Student s2=new Student(); s2.setBirthday(new Date()); s2.setId(001); s2.setName("jy"); Student s1=new Student(); s1.setBirthday(new Date()); s1.setId(002); s1.setName("jq"); list.add(s1); list.add(s2); return list; }}
- 第四步,发布服务
package com.scut.server;import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;import com.scut.dao.impl.StudentServiceImpl;public class StudentServer {public static void main(String[] args) { JAXRSServerFactoryBean jaxrsServerFactoryBean=new JAXRSServerFactoryBean(); jaxrsServerFactoryBean.setAddress("http://127.0.0.1:12345/rest"); jaxrsServerFactoryBean.setServiceBean(new StudentServiceImpl()); jaxrsServerFactoryBean.setResourceClasses(StudentServiceImpl.class); jaxrsServerFactoryBean.create();}}
需要设置servicebean,address和ResourseClass
- 第五步,浏览器上验证服务是否开启
阅读全文
0 0
- cxf发布rest风格的webService
- cxf实现rest风格的webservice
- maven 项目 cxf+spring 发布rest风格webservice
- 8、CXF与Spring整合发布http rest 风格的WebService服务
- webservice--CXF发布REST的服务
- 基于CXF 发布 restful风格的webservice
- spring整合cxf方式发布的rest webservice,调用接口
- webservice--CXF+Spring整合发布REST的服务
- 使用CXF发布基于maven的REST webservice接口
- spring整合cxf 发布restFul风格的webservice
- webService的rest风格的接口发布流程
- CXF WebService 7 - Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- Spring整合CXF,发布RSETful 风格WebService
- windows环境使用composer安装YII2.0
- tensorflow53 《面向机器智能的TensorFlow实战》笔记-05-01 卷积基础
- fl2440串口编程
- Java Web----实训项目第一阶段
- 创建位图索引
- cxf发布rest风格的webService
- linux find exec rm
- 在linux发布网上商城案例
- Unity ResUpdater研究使用1
- Linux特训之vi编辑器part 1(基本操作)
- 面向对象中的String
- myeclipse或eclipse引入mybatis
- 最长公共子序列问题(LCS)
- python中的reduce函数