博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CXF+Spring+Hibernate实现RESTful webservice服务端示例
阅读量:7026 次
发布时间:2019-06-28

本文共 6011 字,大约阅读时间需要 20 分钟。

  hot3.png

1. RESTful API接口定义

 

/*  * Copyright 2016-2017 WitPool.org All Rights Reserved. *  * You may not use this file except in compliance with the License. * A copy of the License is located at *  http://www.witpool.org/licenses *  * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */package org.witpool.rest;import javax.ws.rs.DELETE;import javax.ws.rs.GET;import javax.ws.rs.POST;import javax.ws.rs.PUT;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import org.witpool.common.model.bean.WitEntity;import org.witpool.common.model.po.WitAccount;/**  * @ClassName: IWitAccount  * @Description: Account service definition  * @author Dom Wang  * @date 2017-11-11 AM 11:21:55  * @version 1.0  */@Path("/account")public interface IWitAccount{    /**    *     *    * @Title: addAccount     * @Description: Add account    * @param @param account    * @param @return         * @return WitEntity
* @throws */ @POST WitEntity
addAccount(WitAccount account); /** * * * @Title: updateAccount * @Description: Update account * @param @param account * @param @return * @return WitEntity
* @throws */ @PUT WitEntity
updateAccount(WitAccount account); /** * * * @Title: delAccount * @Description: Delete account by user ID * @param @param userId * @param @return * @return WitEntity
* @throws */ @DELETE @Path("/{userId}") WitEntity
delAccount(@PathParam("userId") Integer userId); /** * * * @Title: getAccount * @Description: Query account by user ID * @param @param userId * @param @return * @return WitEntity
* @throws */ @GET @Path("/{userId}") WitEntity
getAccount(@PathParam("userId") Integer userId); /** * * * @Title: getAccount * @Description: Query all the accounts * @param @param userId * @param @return * @return WitEntity
* @throws */ @GET @Path("/all") WitEntity
getAccounts();}

 

 

2. CXF与Spring的集成配置

 

 

 

3.Spring与Hibernate的集成配置

classpath:resources.properties
org.witpool.common.model.po
${hibernate.dialect}
${hibernate.show_sql}
true
${hibernate.query.substitutions}
${hibernate.default_batch_fetch_size}
${hibernate.max_fetch_depth}
${hibernate.generate_statistics}
${hibernate.bytecode.use_reflection_optimizer}
${hibernate.bytecode.use_reflection_optimizer}
${hibernate.hbm2ddl.auto}

 

4.Hibernate的参数配置

hibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.hbm2ddl.auto=updatehibernate.show_sql=truehibernate.query.substitutions=true 1, false 0hibernate.default_batch_fetch_size=16hibernate.max_fetch_depth=2hibernate.bytecode.use_reflection_optimizer=truehibernate.cache.use_second_level_cache=truehibernate.cache.use_query_cache=truehibernate.cache.region.factory_class=org.hibernate.cache.EhCacheRegionFactorynet.sf.ehcache.configurationResourceName=/ehcache_hibernate.xmlhibernate.cache.use_structured_entries=truehibernate.generate_statistics=trueconnection.driver_class=com.mysql.jdbc.Driverconnection.url=jdbc:mysql://localhost:3306/witpool?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=trueconnection.username=rootconnection.password=123456proxool.maximum.connection.count=40proxool.minimum.connection.count=5proxool.statistics=1m,15m,1h,1dproxool.simultaneous.build.throttle=30

5.代码下载、编译、打包

代码下载请访问 GitHub上的

导入工程文件、编译、打包步骤如下:
导入工程文件选择Existing Maven Projects
指定要导入的Maven工程的根目录路径
选择主工程 wit-pluto 运行maven install
在wit-rest的target目录下获取wit-rest.war

6.部署和UT步骤

将编译生成的包wit-rest.war复制到Tomcat 8.5\webapps\,重启 tomcat

UT步骤:
(1). 下载
(2). 双击 JAR包 restclient-1.1.jar 启动工具
导入:
导入用例文件
关于Wisdom REST Client更多的使用帮助,

 

 

转载于:https://my.oschina.net/wdom/blog/1579602

你可能感兴趣的文章
淘宝API开发系列---阿里.聚石塔.开放平台的使用
查看>>
I.MX6 KEY_ROW4 can't as GPIO pin
查看>>
[大数据之Spark]——Actions算子操作入门实例
查看>>
5.4. package / compress and decompress
查看>>
Vuejs——(7)过渡(动画)
查看>>
(二十一)java字符串替换的问题
查看>>
面向服务编程
查看>>
Codeforces Round #309 (Div. 2) B. Ohana Cleans Up
查看>>
用简单的C语言实现多任务轮流切换(模拟操作系统线程机制)
查看>>
android Recyclerview仿京东,滚动屏幕标题栏渐变(启动页面动画)
查看>>
C语言之数值计算--级数算法
查看>>
C++之引用
查看>>
MFC学习笔记之三(粒子系统+怪物简单AI+碰撞检测)
查看>>
ios xmpp研究探索:发送文本消息
查看>>
费用流模板
查看>>
Makefile规则详解
查看>>
明星讲师心石闪耀ArchSummit大会 | 手机淘宝构架演化实践
查看>>
【Android开发】网路编程及Internet应用-从指定网站上下载文件
查看>>
PHP7源码笔记一
查看>>
扩展欧几里得算法求方程特解
查看>>