7–Jersey+SQLServer+Hibernate4.3+Spring3.2

最后更新于:2022-04-01 20:01:36

## 一、总体说明 本例运行演示了用 Jersey 构建 RESTful 服务中,如何集成 Spring3 ## 二、环境 * 1.上文的项目RestDemo * 2.Spring及其他相关的jar ,导入项目  ![Spring及其他相关的jar](http://h.hiphotos.bdimg.com/album/s%3D550%3Bq%3D90%3Bc%3Dxiangce%2C100%2C100/sign=d3d08e3730fa828bd5239de6cd243009/b03533fa828ba61ec73dc21d4234970a304e5934.jpg?referer=743b926cdec451daafe138dba7ea&x=.jpg) ## 三、配置 1.根目录下下创建 Spring 的配置文件`applicationContext.xml`;  配置如下:  ## 四、运行 1.先运行项目 2.运行UserClient.java测试,控制台输出如下 ~~~ ****增加用户addUser**** ****查询所有getAllUsers**** [{"userId":"002","userName":"sdfs","age":"23"},{"userId":"003","userName":"sdfs","age":"23"},{"userId":"004","userName":"sdfs","age":"23"},{"userId":"005","userName":"sdfs","age":"23"},{"userId":"006","userName":"Susan","age":"21"},{"userId":"007","userName":"sdfs","age":"23"},{"userId":"ds","userName":"ds","age":"ds"}] ****修改用户updateUser**** ****根据id查询用户**** 006Susan33 ****查询所有getAllUsers**** [{"userId":"002","userName":"sdfs","age":"23"},{"userId":"003","userName":"sdfs","age":"23"},{"userId":"004","userName":"sdfs","age":"23"},{"userId":"005","userName":"sdfs","age":"23"},{"userId":"006","userName":"Susan","age":"33"},{"userId":"007","userName":"sdfs","age":"23"},{"userId":"ds","userName":"ds","age":"ds"}] ****删除用户**** ****查询所有getAllUsers**** [{"userId":"002","userName":"sdfs","age":"23"},{"userId":"003","userName":"sdfs","age":"23"},{"userId":"004","userName":"sdfs","age":"23"},{"userId":"005","userName":"sdfs","age":"23"},{"userId":"007","userName":"sdfs","age":"23"},{"userId":"ds","userName":"ds","age":"ds"}] ~~~ **本章源码(含jar包)**:[https://github.com/waylau/RestDemo/tree/master/jersey-demo7-sqlserver-hibernate-spring3](https://github.com/waylau/RestDemo/tree/master/jersey-demo7-sqlserver-hibernate-spring3)
';