Spring Boot与JAX-RS(Restlet)的简单微服务 [英] Spring Boot vs. JAX-RS (Restlet) for dead simple microservice

查看:149
本文介绍了Spring Boot与JAX-RS(Restlet)的简单微服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个非常小的独立的微服务,为一些将数据存储在内存中的REST操作提供服务(不需要持久性).

I want to build a really small self-contained microservices serving some REST operations storing the data in memory (no persistence required).

因此,我正在寻找最轻量级的框架方法.在研究了可用的JAX-RS实现之后,Restlet似乎是一个不错的选择.

Hence, I am looking framework-wise for the most lightweight approach. After looking into an available JAX-RS implementations Restlet seemed to be a good choice.

还向Spring Boot推荐了不需要JAX-RS的注释.我有点困惑. JAX-RS是否不是Java REST应用程序的标准?反正我不需要将Spring Boot与JAX-RS结合吗?

Also got Spring Boot recommended with the comment you don't need JAX-RS. I got a bit confused. Isn't JAX-RS the standard for Java REST applications? Wouldn't I need to combine Spring Boot with JAX-RS anyway?

推荐答案

它们是完全不同的野兽,它们两者都可以以自己的方式对您有用.

They're completely different beasts and both of them can be useful to you in their own way.

我会解释:

Spring Boot完全支持Rest服务. Spring Boot之所以大放异彩,是因为您可以在5-6行代码中按字面意义创建一个Rest服务.

Spring boot perfectly supports Rest services. Spring boot shines because you can create a rest service literally in 5-6 lines of code.

春季启动将:

  • 处理Web容器(它嵌入了tomcat/jetty,尽管您也可以选择将战争部署在外部)

  • handle web container (it has tomcat/jetty embedded, although you might opt for wars to be deployed externally as well)

处理所有依赖项(版本合规性,因此强制执行).它还意味着JSON操作框架,而不仅仅是声明REST端点的方式.默认情况下,Spring Boot使用Jackson.

Handle all the dependencies (version compliance and so force). It also means JSON manipulation framework and not just the way of declaring REST endpoints. Spring boot uses Jackson by default.

处理打包所有内容的所有麻烦.如果您使用WAR,它可能会变得不那么有趣(当然,在这种情况下,您必须考虑使用Web容器,而Spring Boot会为您做到这一点).但是您使用的是Jars-Spring Boot会创建一个可以用java -jar <youjar>加载的大jar.

Handle all the hassle of packaging everything. If you work with WAR it can be less interesting (of course, in this case you'll have to think about the web-container and spring boot does it for you). But you work with Jars - spring boot will create one big jar that just can be loaded with java -jar <youjar>.

(可选)为您的应用程序提供指标和JMX内容-只需声明对执行器的maven/gradle依赖关系就可以了.

Optionally providing a metrics and JMX stuff for your application - just declare a maven/gradle dependency on actuator and you're ready to go.

所有这些使spring boot成为开发独立的微服务的理想之选,这可能就是您的情况.

All this makes spring boot perfect for developing self-contained microservices which might be your case.

相反,如果您正在寻找可以在现有解决方案上提供支持的框架,则可能不会使用spring boot.也许您根本不使用spring,谁知道?

On the opposite If you're looking for framework to provide rest on your existing solution, than probably you won't use spring boot. Maybe you're not using spring at all, who knows?

所以我要说,Jersey/Restlet等只是Web框架,可以更轻松地用Java开发REST服务. Spring Boot不仅仅是管理您的应用程序,它还提供了一种使用REST服务的方式,就像它提供了一种使用JDBC,Servlet API等的方式一样.

So I would say, that Jersey/Restlet and so forth are just Web frameworks for easier development of REST services in Java. And spring boot is more about managing your application, of course it provides also a way of working with REST services just like it provides a way of working with JDBC, Servlet API and so forth.

希望这会有所帮助

这篇关于Spring Boot与JAX-RS(Restlet)的简单微服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆