# CXF-RestOrJsonOrSoap
**Repository Path**: lsl520/CXF-RestOrJsonOrSoap
## Basic Information
- **Project Name**: CXF-RestOrJsonOrSoap
- **Description**: 集成CXF发布WebServer服务(SOAP,RESTful,JSON)
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 1
- **Created**: 2016-11-17
- **Last Updated**: 2020-12-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 集成CXF发布WebServer服务(SOAP,RESTful,JSON)
---
## 项目介绍
> CXF结合spring发布WS服务,含SOAP services、RESTful services
不想听废话,直接上代码
代码URL: [GITHUB走你{我是代码;}](https://github.com/27786653/CXF-RestOrJsonOrSoap)
个人博客:[CSDN](http://blog.csdn.net/qqqqq210/article/details/53198620)
1. RESTful:在包com.yuhi.webservice.rest下
2. SOAP:在包com.yuhi.webservice.romte下
3. BaseWsRespnose序列化数据返回
4. 服务列表可访问:http://localhost:8080/Spring-CXF/ws/
### applicationContext.xml
```
```
### soap实现
```
//接口
@WebService
public interface HelloWorld {
String sayHi(String text);
}
//实现类
@WebService(endpointInterface = "com.yuhi.webservice.romte.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
System.out.println("sayHi called");
return "Hello " + text;
}
}
```
### restful实现
```
@Component
public class FooBarWS extends BaseWsRespnose {
@Autowired
private FooBarService fooBarService;
@GET
@Path("/{param}")
public Response getMessage(@PathParam("param") String msg) {
String respnosemes=fooBarService.getMessage(msg);
return respnoseStringMes(respnosemes);
}
@GET
@Path("/mes/{id}")
public Response getbooks(@PathParam("id") String id) {
UserInfo b=new UserInfo();
b.setAccount("authon"+id);
b.setId(id);
b.setName("id:"+5.0);
return respnoseJsonMes(b);
}
public FooBarService getFooBarService() {
return fooBarService;
}
public void setFooBarService(FooBarService fooBarService) {
this.fooBarService = fooBarService;
}
}
```
### pom依赖
```
4.0.0
com.yuhi
CXF-RestOrJsonOrSoap
war
1.0-SNAPSHOT
CXF Maven
http://maven.apache.org
3.1.0.RELEASE
2.7.18
com.alibaba
fastjson
1.2.7
org.apache.cxf
cxf-rt-frontend-jaxws
${cxf.version}
org.apache.cxf
cxf-rt-frontend-jaxrs
${cxf.version}
org.apache.cxf
cxf-rt-transports-http
${cxf.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-core
${spring.version}
org.springframework
spring-oxm
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.apache.maven.plugins
maven-war-plugin
2.1.1
maven-compiler-plugin
1.5
1.5
Spring-CXF
```
### web.xml
```
Spring CXF
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
CXF Servlet
CXFServlet
org.apache.cxf.transport.servlet.CXFServlet
2
CXFServlet
/ws/*
```