参考 https://www.cnblogs.com/fuxin41/p/6289162.html

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.xx</groupId>
<artifactId>webservice</artifactId>
<version>0.0.1-dev-SNAPSHOT</version>
<packaging>war</packaging> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-oracle</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

WebServiceConfig.java

package com.xx.ws.config;

import com.xx.ws.service.UserService;
import com.xx.ws.service.UserServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import javax.xml.ws.Endpoint; @Configuration
public class WebServiceConfig {
@Bean
public ServletRegistrationBean dispatcherServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/ws/*");
} @Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
} @Bean
public UserService userService() {
return new UserServiceImpl();
} @Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), userService());
endpoint.publish("/userService");
return endpoint;
}
}

UserService.java

package com.xx.ws.service;

import com.xx.ws.entity.DataEntity;
import com.xx.ws.entity.ResponseEntity;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.util.List; @WebService
public interface UserService {
@WebMethod
ResponseEntity createUser(@WebParam(name="data") DataEntity data); @WebMethod
ResponseEntity updateUser(@WebParam(name="guid") String guid, @WebParam(name="data") DataEntity data); @WebMethod
ResponseEntity deleteUser(@WebParam(name="guid") String guid); @WebMethod
List<DataEntity> queryByIds(@WebParam(name="ids") List<String> ids);
}

UserServiceImpl.java

package com.xx.ws.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.jws.WebService; import com.xx.ws.SecDao;
import com.xx.ws.entity.DataEntity;
import com.xx.ws.entity.ResponseEntity;
import com.xx.ws.util.RsaUtil;
import org.springframework.beans.factory.annotation.Autowired; @WebService(endpointInterface="com.xx.ws.service.UserService",
targetNamespace="http://service.ws.xx.com/")
public class UserServiceImpl implements UserService {
@Autowired
private SecDao secDao; public ResponseEntity createUser(DataEntity data) {
Map<String, String> attrs = data.getAttrs();
String userId = attrs.get("userId");
String roleId = attrs.get("roleId"); String uuid = getUUID(); ResponseEntity resp;
boolean exi = secDao.exist(userId);
boolean roleexi = secDao.existRole(roleId);
if (exi) {
resp = new ResponseEntity("用户已存在", "300", uuid, false);
} else if (!roleexi) {
resp = new ResponseEntity("不存在该权限", "300", uuid, false);
} else {
secDao.save(userId, attrs.get("userName"), attrs.get("password"), roleId);
resp = new ResponseEntity("success!!!", "200", uuid, true);
} return resp;
} public ResponseEntity updateUser(String guid, DataEntity data) {
Map<String, String> attrs = data.getAttrs();
String userId = guid;
String roleId = attrs.get("roleId"); String uuid = getUUID(); ResponseEntity resp;
boolean exi = secDao.exist(userId);
boolean roleexi = secDao.existRole(roleId); if (!exi) {
resp = new ResponseEntity("不存在该用户", "300", uuid, false);
} else if (!roleexi) {
resp = new ResponseEntity("不存在该权限", "300", uuid, false);
} else {
secDao.update(userId, attrs.get("userName"), attrs.get("password"), roleId);
resp = new ResponseEntity("success!!!", "200", uuid, true);
} return resp;
} public ResponseEntity deleteUser(String guid) {
ResponseEntity resp;
String uuid = getUUID();
boolean exi = secDao.exist(guid);
if (!exi) {
resp = new ResponseEntity("不存在该用户", "300", uuid, false);
} else {
secDao.delete(guid);
resp = new ResponseEntity("success!!!", "200", uuid, true);
} return resp;
}// queryByIds方法
public List<DataEntity> queryByIds(List<String> ids) {
List<Map<String, Object>> objectDatas = secDao.getByIds(ids); List<DataEntity> datas = new ArrayList<DataEntity>();
for (int i = 0; i < objectDatas.size(); i++) {
Map<String, String> map = new HashMap<String, String>();
Map<String, Object> tmp = objectDatas.get(i); map.put("userId", tmp.get("userId") + "");
map.put("userName", tmp.get("userName") + "");
map.put("roleId", tmp.get("roleId") + ""); DataEntity data = new DataEntity();
data.setAttrs(map); datas.add(data);
} return datas;
} private String getUUID() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
}

Application.java

package com.xx.ws;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

ServletInitializer.java  如果需要打成war包,增加此文件

package com.xx.ws;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer; /**
* Created by Administrator on 2017/11/14.
*/
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}

springboot+cxf 开发webservice的更多相关文章

  1. springboot+CXF开发webservice对外提供接口(转)

    文章来源:http://www.leftso.com/blog/144.html 1.项目要对外提供接口,用webservcie的方式实现 2.添加的jar包 maven: <dependenc ...

  2. struts1+spring+myeclipse +cxf 开发webservice以及普通java应用调用webservice的实例

    Cxf + Spring+ myeclipse+ cxf 进行  Webservice服务端开发 使用Cxf开发webservice的服务端项目结构 Spring配置文件applicationCont ...

  3. 使用cxf开发webservice应用时抛出异常

    在使用cxf开发webservice应用时,报出了类似下面的错误 JAXB: [javax.xml.bind.UnmarshalException: unexpected element (uri:& ...

  4. 【WebService】使用CXF开发WebService(四)

    CXF简介 Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF.CXF 继承了 Celtix ...

  5. 使用cxf开发webservice接口

    项目中经常用到开发webservice接口,及调用webService接口.这里讲解如何使用cxf开发webService接口. 一.webservice介绍及理解 webservice是一种跨平台, ...

  6. 3.使用CXF开发webService

    CXF 简介 关于 Apache CXF Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache ...

  7. Spring boot+CXF开发WebService

    最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...

  8. Spring boot+CXF开发WebService Demo

    最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...

  9. (三)使用CXF开发WebService客户端

    前面一讲开发了webservice服务器端接口,今天的话,我们来开发webservice客户端,让大家来体验下过程: 首先建一个Maven项目,项目名字,WS_Client: 然后我们要用CXF给我们 ...

随机推荐

  1. 2013-8-6 ubuntu基本操作

    1,apt-get下载文件默认安装路径 apt-get 下载后,软件所在路径是什么?? /var/cache/apt/archives ubuntu 默认的PATH为 PATH=/home/brigh ...

  2. HDFS高级开发培训课程之HDFS开发实例课件

    前言: 刚刚完成的HDFS高级开发培训课程课件中的一个章节,不知道PPT,如何导出HTML格式,只好批量导出图片,贴图了. 连接管理:建立连接.断开连接.设置连接参数 文件操作:浏览文件.上传文件.下 ...

  3. git如何查看某个人提交的日志。

    我们知道,在git进行cherry-pick的时候,找到commit id是至关重要, 如果我们是很多人在一个分支开发,开发完了之后,发现某个人的功能,需要单独cherry-pick到另外一分支上去. ...

  4. elastix php session保存地点

    这段时间要做 asterisk 的HA 放啊,需要同步session,所以做了下来研究. 1)elastix中的session 其实是存放在 /tmp/目录中的.可是/etc/php.ini中的[se ...

  5. python学习之----用虚拟环境保存库文件

    如果你同时负责多个Python 项目,或者想要轻松打包某个项目及其关联的库文件,再 或者你担心已安装的库之间可能有冲突,那么你可以安装一个Python 虚拟环境来分而 治之. 当一个Python 库不 ...

  6. 在oracle下如何创建database link全面总结

    物理上存放于网络的多个ORACLE数据库,逻辑上可以看成一个单一的大型数据库,用户可以通过网络对异地数据库中的数据进行存取,而服务器之间的协同处理对于工作站用户及应用程序而言是完全透明的,开发人员无需 ...

  7. 一、探索 Android Studio

    探索 Android Studio 本文内容 项目结构 界面 Gradle 构建系统 调试和分析工具 Android Studio 是基于 IntelliJ IDEA 的官方 Android 应用开发 ...

  8. python3调用C动态库

    软硬件环境 OS X EI Capitan Python 3.5.1 GCC 4.9 前言 最近在做python3开发中,碰到了一个问题,需要通过调用C的一个动态链接库来获取相应的值.扒了扒网络,动手 ...

  9. centos73下php5.6安装GD库

    yum --enablerepo=remi-php56 install php-gd php-mysql php-mbstring php-xml php-mcrypt YUM安装的 找到了源  分分 ...

  10. jdk配置(备份)

    #####set java environment #export JAVA_HOME=/usr/java/jdk1..0_172 #export JRE_HOME=${JAVA_HOME}/jre ...