真正的实现没有区别。 将Spring与Jersey集成以及将Jersey与Spring集成

More interesting and arguably references are Jersey and Spring, especially integrating Jersey to Spring, or differ. This article we might response that curiosity. Catch up source code which we implemented Spring and Jersey.
Really there is no difference in implementation. Integrating Spring with
Jersey and integrating Jersey with Spring mean the same thing as far as code
is concerned.

What is Jersey, stands for...?

简要介绍一下Jersey:Jersey RESTful Web服务框架是开源,生产质量,用于以Java开发RESTful Web服务的框架,该框架提供对JAX-RS API的支持并用作JAX-RS(JSR 311和JSR 339)参考实现 。

What is JAX-RS...?

RESTful Web服务的Java API(JAX-RS)是Java编程语言API规范,它提供了根据代表性状态转移(REST)架构模式创建Web服务的支持。 JAX-RS使用注释来简化Web服务客户端和端点的开发和部署。 JAX-RS是Java EE的正式组成部分。

本文假定您了解Jersey,并正在考虑将Spring集成到Jersey应用程序中。 图1。 三层应用程序体系结构。

Alt Text

图1。 三层应用程序体系结构。

在此示例中,业务层和持久性层可能看起来是多余的,但是在实际应用中,服务层还处理域的业务逻辑,不仅是简单的“查找数据”,而且是“处理数据”。 持久层应仅与数据库交互有关,而与任何业务逻辑无关。 在REST应用程序中,没有表示层。 但这是否意味着该体系结构不适用于REST应用程序? 绝对不。 我们仍应在REST应用程序中坚持关注点分离。 这只是一个好的设计。 使用Spring,其REST层在其MVC框架中实现。 MVC框架通过使用控制器的MVC功能而广为人知。 但是,只要对控制器和使用的注释进行一些调整,这些控制器就可以轻松地成为REST控制器,您可以在其中代替返回模型和视图,而返回RESTful表示对象。 更多有价值的信息请参见图2。 基于“ Demeter法则”的多层体系结构。

Alt Text
Figure-2. Multi-layer architecure.

  • 第一层是通过Jersey实施的REST支持,具有立面的作用并将逻辑委托给业务层业务层是逻辑发生的地方数据访问层是与持久性存储(在您的情况下为MySql数据库)进行通信的地方

小号ource code:

 @SpringBootApplication
 public class JerseyApplication implements WebApplicationInitializer {

  public static void main(String[] args) {
    SpringApplication.run(JerseyApplication.class, args);
  }

  @Override
 public void onStartup(ServletContext sc) throws ServletException {
    sc.setInitParameter("contextConfigLocation", "noop");

    AnnotationConfigWebApplicationContext context
            = new AnnotationConfigWebApplicationContext();
    context.register(SpringConfig.class);
    sc.addListener(new ContextLoaderListener(context));
    sc.addListener(new RequestContextListener());
 }

参考:

  1. WHY AND HOW TO USE SPRING WITH JERSEY?
  2. Tutorial – REST API design and implementation in Java with Jersey and Spring

from: https://dev.to//urunov/truly-there-is-no-difference-in-implementation-integrating-spring-with-jersey-and-integrating-jersey-with-spring-m2k

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值