8
votes

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

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.

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?

2

2 Answers

11
votes

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

I'll explain:

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

Spring Boot will:

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

  • 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.

  • 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>.

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

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

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?

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.

1
votes

JAX-RS is part of the Java EE specification and the standard REST API for application servers, which implement the Java EE specification. Each application server usually comes with it's own implementation, let it be RestEasy for Wildfly, Jersey, Wink etc.
It doesn't mean, that every Java framework which supports REST, has to implement JAX-RS. That said, Restlet is not a JAX-RS implementation, it's a completely independent framework (as Spring MVC with its REST capabilities is, which would be used by default by Spring Boot).

You can also develop a Spring Boot application with JAX-RS for REST, Spring Boot provides starter POMs for Jersey and also autoconfiguration to minimize your own configuration efforts.