jersey2.26+spring5+jpa一步步搭建restful服务

时间:2021-01-10 19:35:25

前言

 首先,为什么想选择Jersey做restful服务呢?我个人比较喜欢它的插件化设计,可以方便的注入自己的全局处理逻辑。再一个就是可以生成wadl描述文件,供查询服务方法。所以在学习spring的过程中,特意抽时间做了jersey+spring集成的验证。在本次搭建的过程中,为了在jersey服务中启动spring事务,从网上查阅了不少。先是看到com.sun.jersey例子,后来发现版本比较低,后转过头去看org.glassfish.jersey。吭吭哧哧服务启动了,却又发现无法通过spring容器实例化服务,无法开启事务,拿不到懒加载数据。又查阅资料来回调试,解决版本不匹配的问题,将jersey-spring3升级成jersey-spring4。摸索的过程总是枯燥的,好在总算是一个个问题的排查解决,终究实现了自己想要的功能! 在这里把我自己摸索过程中涉及到的重点位置分享给大家,希望能对大家有所帮助。

一、关于Jersey

 Jersey RESTful 框架是开源的RESTful框架, 实现了JAX-RS (JSR 311 & JSR 339) 规范。它扩展了JAX-RS 参考实现, 提供了更多的特性和工具, 可以进一步地简化 RESTful service 和 client 开发。尽管相对年轻,它已经是一个产品级的 RESTful service 和 client 框架。与Struts类似,它同样可以和hibernate,spring框架整合。

 jersey1.X使用的是sun的com.sun.jersey

 jersey2.X使用的是glassfish的org.glassfish.jersey

二、集成环境说明

 Java:1.8.0_152、SpringMVC:5.0.1.RELEASE、Jersey:2.26-b04、开发工具:eclipse、涉及技术点:springmvc,spring-security,spring data jpa,jersey

三、项目结构简介

 3.1、simm.spring.web是web层,simm.spring.restapi是jersey服务层

 ·jersey2.26+spring5+jpa一步步搭建restful服务

 3.2、父级spring-web的POM文件中配置spring jar包依赖

jersey2.26+spring5+jpa一步步搭建restful服务jersey2.26+spring5+jpa一步步搭建restful服务
<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>
<parent>
<groupId>simm.study</groupId>
<artifactId>spring-study</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>spring-web</artifactId>
<packaging>pom</packaging>
<properties>
<springframework.version>5.0.1.RELEASE</springframework.version>
<!--下面这两个是springAOP需要用到 -->
<aspectjweaver.version>1.9.0.RC2</aspectjweaver.version>
<persistence-api.version>1.0.2</persistence-api.version>
<hibernate.version>5.2.12.Final</hibernate.version>
<json.version>2.9.2</json.version>
<security-version>5.0.0.RELEASE</security-version>
<logback.version>1.1.1</logback.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${json.version}</version>
</dependency>
<!-- 4)springmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- springmvc-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<!--下面两个提供对 AspectJ 的支持,是 springmvc-aspects 所需要依赖的 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectjweaver.version}</version>
</dependency>
<!-- 这个jar包与hibernate持久化功能冲突,去掉 -->
<!-- <dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
</dependency>
-->
<!--这个一定要有、不用报错 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${security-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${security-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${security-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.27-incubating</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Logback dependencies -->
<!--<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.3.5.jre8-preview</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<!-- jpa 2.0以上的版本 需要 spring framework 5 以上支持 -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
</dependencies>
<modules>
<module>simm.spring.web</module>
<module>simm.spring.dao</module>
<module>simm.spring.entity</module>
<module>simm.spring.service</module>
<module>simm.spring.common</module>
<module>simm.spring.restapi</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
View Code

   3.3、simm.spring.restapi子项目下的POM文件中配置jersey jar包依赖。jersey-spring4这个jar包是jersey,spring框架整合的关键,起桥接作用,使用时可根据需要排除掉jersey指定的jar包文件。

jersey2.26+spring5+jpa一步步搭建restful服务jersey2.26+spring5+jpa一步步搭建restful服务
<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>
<parent>
<groupId>simm.study</groupId>
<artifactId>spring-web</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>simm.spring.restapi</artifactId>
<name>restful-server</name>
<description>restful-server</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jersey.version>2.26-b04</jersey.version>
<jersey-spring.version>2.26-b04</jersey-spring.version>
<servlet-api-version>3.1.0</servlet-api-version>
<jcloverslf4j.version>1.7.6</jcloverslf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring4</artifactId>
<version>${jersey-spring.version}</version>
<exclusions>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>jersey-container-servlet-core</artifactId>
<groupId>org.glassfish.jersey.containers</groupId>
</exclusion>
<exclusion>
<artifactId>hk2</artifactId>
<groupId>org.glassfish.hk2</groupId>
</exclusion>
<exclusion>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</exclusion>
<exclusion>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-entity-filtering</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${jcloverslf4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.44</version>
</dependency>
<dependency>
<groupId>simm.study</groupId>
<artifactId>simm.spring.entity</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>simm.study</groupId>
<artifactId>simm.spring.dao</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>simm.study</groupId>
<artifactId>simm.spring.common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
View Code

四、在web.xml中配置jersey请求的sevlet容器

 4.1、web.xml配置文件展示

jersey2.26+spring5+jpa一步步搭建restful服务jersey2.26+spring5+jpa一步步搭建restful服务
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>my springmvc</display-name>
<!-- 配置上下文的 spring.profiles.active -->
<!-- https://www.cnblogs.com/vanl/p/5759671.html -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>mysql</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application-*.xml,classpath*:jdbc-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- servlet 容器的配置 -->
<servlet>
<!-- 配置DispatcherServlet -->
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 设置启动顺序 指定spring mvc配置文件位置 不指定使用默认情况 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>/WEB-INF/spring-mvc.xml,classpath*:/applicationContext.xml</param-value> -->
<param-value></param-value>
</init-param>
<!-- 多媒体文件上传配置,该配置意味着启用标准的多媒体解析器StandardServletMultipartResolver -->
<load-on-startup>1</load-on-startup>
<multipart-config>
<location/>
<!-- 临时目录可以不配置,默认是""
<location>/tmp</location> 上传文件的大小限制,示例:5M
-->
<max-file-size>5242880</max-file-size>
<!-- 一次表单提交中文件的大小限制,示例:10M -->
<max-request-size>10485760</max-request-size>
<!-- 多大的文件会被自动保存到硬盘上。0 代表所有 -->
<file-size-threshold>0</file-size-threshold>
</multipart-config>
</servlet>
<!-- 配置映射 servlet-name和DispatcherServlet的servlet一致
静态资源要通过 DispatcherServlet 进行分发,这样才能进行版本解析
-->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!-- 拦截以/所有请求,服务端请求可以自己添加 .do 后缀即可 -->
<url-pattern>*.do</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>JerseyServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<!-- 这个类是资源注册类 -->
<param-value>simm.spring.restapi.config.MyRestfulService</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- =================== HiddenHttpMethodFilter end ==================== -->
<servlet-mapping>
<servlet-name>JerseyServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<!-- 配置 end -->
<welcome-file-list>
<welcome-file>/free/list.do</welcome-file>
</welcome-file-list>
</web-app>
View Code

  4.2、关于contextConfigLocation与listener的配置简单说明

 搭建过程中,发现启动项目时老是提示找不到applicationContext.xml文件。通过调试代码,发现jersey-spring4-2.26-b04.jar下继承接口WebApplicationInitializer实现了启动类 SpringWebApplicationInitializer。这段逻辑会从WebApplicationContext中去读取contextConfigLocation配置项,假如读不到值就会自动设置初始化路径applicationContext.xml。因此就有了web.xml文件中的context-param>contextConfigLocation 的配置,根据源码配置系统全局监听器ContextLoaderListener和RequestContextListener。全局监听的配置可以保证jersey的servlet容器同样能够读取到spring容器中的对象。

  jersey2.26+spring5+jpa一步步搭建restful服务

 4.3、关于jersey请求的servlet容器配置说明

  • servlet-class:org.glassfish.jersey.servlet.ServletContainer
  • servlet-mapping>url-pattern:/api/*,即restful服务请求从api层级开始
  • init-param[javax.ws.rs.Application]:simm.spring.restapi.config.MyRestfulService,这个类是自己项目对jersey的配置说明,声明自己的resouce服务路径,并注册一些全局插件

 jersey2.26+spring5+jpa一步步搭建restful服务

 4.4、simm.spring.restapi.config.MyRestfulService 类源码说明。

 在网上查阅资料时,有些文章指出需要注入 RequestContextFilter过滤器,个人测试示例中发现还没有受到影响,在我的代码里不用这个过滤器也照样可以正常运行。可能还没有涵盖到这块功能。调用packages方法,指定服务资源所在的包名。此外,还注册了json、log、异常处理、跨域处理几个插件。

package simm.spring.restapi.config;

import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;

public class MyRestfulService extends ResourceConfig {
public MyRestfulService(){
// 需要注入spring组件解析过滤器
register(RequestContextFilter.class);
// 加载resources
packages("simm.spring.restapi.resource");
// 注册数据转换器
register(JacksonFeature.class);
// 注册日志
register(LoggingFeature.class);
// 异常处理
register(ExceptionHandler.class);
// 跨域过滤器注册
register(CorsFilter.class);
}
}
  • 异常处理器代码
@Provider
public class ExceptionHandler implements ExceptionMapper<Exception> {
public Response toResponse(Exception exception) {
// TODO Auto-generated method stub
//LogKit.error(exception.getMessage(), exception);
return Response.serverError().entity(new JsonResult(false,exception.getMessage(),exception.toString())).build();
}
}
  • 跨域过滤器代码
package simm.spring.restapi.config;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

public class CorsFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext creq, ContainerResponseContext cres) {
// TODO Auto-generated method stub
cres.getHeaders().add("Access-Control-Allow-Origin", "*");
/**
* 允许的Header值,不支持通配符
*/
cres.getHeaders().add(
"Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
cres.getHeaders().add(
"Access-Control-Allow-Credentials", "true");
/**
* 即使只用其中几种,header和options是不能删除的,因为浏览器通过options请求来获取服务的跨域策略
*/
cres.getHeaders().add(
"Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
/**
* CORS策略的缓存时间
*/
cres.getHeaders().add(
"Access-Control-Max-Age", "1209600");
}
}

 五、实现一个自己的resource服务ProcessBlockResource

 5.1、ProcessBlockResource源码展示

jersey2.26+spring5+jpa一步步搭建restful服务jersey2.26+spring5+jpa一步步搭建restful服务
package simm.spring.restapi.resource;

import java.util.*;
import javax.ws.rs.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONObject;
import simm.spring.common.utils.JpaUtil;
import simm.spring.entity.ProcessBlock;
import simm.spring.restapi.config.MediaTypeExtend;

@Path(
"processblock")
@Produces(MediaTypeExtend.APPLICATION_JSON_UTF8)
@Component
@Scope(
"request")
public class ProcessBlockResource {
@Autowired
private JpaUtil _jpaUtil;
@POST
@Path(
"getlist")
@Transactional
public List<JSONObject> getList(@FormParam("name") String name) {
JpaUtil jpaUtil
= _jpaUtil;//ApplicationContextUtil.instance.getJpaUtil();
Map<String, Object> params = new HashMap<>();
params.put(
"name", name);
List
<ProcessBlock> list = jpaUtil.list(
"select u from simm.spring.entity.ProcessBlock u where u.name=:name", params, ProcessBlock.class);
//System.out.println("准备获取懒加载数据");
//Set<Node> nodes = list.get(0).getNodeSet();
List<JSONObject> rows = new ArrayList<JSONObject>();
list.forEach(a
->{
JSONObject obj
= new JSONObject();
obj.put(
"Id",a.getId());
obj.put(
"Class",a.getClass());
obj.put(
"Name",a.getName());
obj.put(
"Description",a.getDescription());
obj.put(
"SubClass",a.getSubClass());
//NodeSet 是懒加载对象,如果直接json输出ProcessBlock对象会导致 因session关闭,无法获取关联数据的异常。
//这里显示的执行一次调用,需要返回的数据最好自己做一次组装
obj.put("NodeSet",a.getNodeSet().toArray());
rows.add(obj);
});
return rows;
}
}
View Code

 5.2、源码简要解析

  • ProcessBlockResource类注解说明
  1. @Path:指定资源名为 processblock
  2. @Produces:指定资源下服务方法默认返回json格式数据
  3. @Component,@Scope("request"):将资源声明为一个请求级别的bean组件,解析后交由spring代理进行实例化
  • getList方法注解说明
  1. @POST:声明为post请求
  2. @Path:指定服务名为 getlist
  3. @Transactional:声明开启spring事务对方法的拦截,后面我们会测试事务是否生效

 5.3、启动Tomcat,查看restful服务启动状态。可以访问application.wadl,得到restful服务描述文件。

  jersey2.26+spring5+jpa一步步搭建restful服务

 5.4、使用SoapUI工具测试一下/processblock/getlist服务

  从调用返回可以看到,服务调用成功,并成功获取到了懒加载数据NodeSet。说明现在spring容器已经与jersey结合起来,组件初始化以及spring事务的拦截功能都已经正常运转。接下来我们就可以按照这个示例实现自己的restful服务了。关于getList方法中涉及到的实体类以及工具类,如果有需要,请大家参考上篇博文《JPA数据懒加载LAZY配合事务@Transactional使用(三)

   jersey2.26+spring5+jpa一步步搭建restful服务

   至此,jersey+spring5的搭建就完成了。感谢你阅读到最后,如果你有好的意见或建议,欢迎留言,大家一起交流,共同进步。

参考资料

http://blog.csdn.net/u013628152/article/details/42126521
http://momoxiaoxiong.iteye.com/blog/1214238
https://yq.aliyun.com/articles/47170
https://www.cnblogs.com/vanl/p/5759671.html
http://blog.chinaunix.net/uid-28215567-id-3363225.html