How to use RESTEasy in a Spring Boot application
By Fábio Carvalho | August 9, 2017
Spring Boot
Spring Boot is Spring "convention-over-configuration" solution for creating stand-alone, production-grade Spring-based Applications, usually contained in a single and executable jar. It is also an opinionated framework, allowing Spring platform and third-party libraries to be auto-configured, minimizing the need for boilerplate code.
One of the most important concepts in Spring Boot is the notion of "starter". According to Spring Boot reference guide, "starters are a set of convenient dependency descriptors that you can include in your application". Another way to see starters is as "the building blocks that leverage auto-configuration when extending your application with Spring or other third-party components".
Because of all features Spring Boot offers, it ends up being a very convenient platform to build Java microservices applications, especially considering that Spring Boot has also starters for embedded Servlet containers, such as Tomcat and Jetty.
RESTEasy and Spring Boot
When it comes to JAX-RS applications, Spring Boot applications can also be RESTEasy applications, and that is possible by using RESTEasy Spring Boot starter, which is an open source project initially developed by PayPal, and endorsed by RESTEasy team.
Using RESTEasy in a Spring Boot application
Using RESTEasy in a Spring Boot application is very simple, just follow the steps below.
- Add dependency
com.paypal.springboot:resteasy-spring-boot-starter
to your Spring Boot application (it is recommended to use the latest version). - Optionally, register one or more JAX-RS Application classes. To do so, just define it as a Spring bean, and it will be automatically registered.
- Finally, to register JAX-RS resources and providers, just define them as Spring beans, and they will be automatically registered.
Notice that JAX-RS resources can be singleton or request scoped, while JAX-RS providers must be singletons.
See this RESTEasy Spring Boot sample application as an example.
References
Useful Links
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor