Spring Boot Jersey Example

Spring Boot Jersey Example:-

Today we are going to learn about configuring Spring Boot and Jersey. We can create Rest services in Spring using spring @RestController, then Why do we want to integrate Jersey in Spring Boot.Let’s try and understand this first.

You must be knowing about JAX-RS. JAX-RS is a specification for implementing REST web services in Java, currently defined by the JSR-370. Jersey is the pure reference implementation of JAX-RS. Spring is a framework itself having Rest support.Spring RestController is not a JAX-RS reference implementation, but it’s an alternative. Spring Rest is not a core implementation of JAX-RS.




Project Structure:-

Spring Boot And Jersey

 

 

 

 

 

 

 




Project Dependencies:-

Declare spring-boot-starter-jersey as your dependency, as we use Jersey in our project.



Configure Spring Boot Jersey Rest Endpoints:-

Configure Spring Boot Jersey:-

Create a file JerseyConfig.java and add the following piece of code. Here we are configuring /api as the base context of the web service. We are going to register all jersey based resources under package com.frugalis.resources  so that we can access it from our spring boot application .We have already created one above (UsersResource )which is under  package com.frugalis.resources .  Hence we need not explicitly register that resource.

In the end, the difference in choosing between them usually comes down as  Are you already or do you plan to integrate any other Spring libraries into your application? If so Spring REST is the way to go as you’ll have a much easier time integrating it, otherwise, it is really just personal preference which you’d prefer to use.

If your project has chances of getting migrated to different frameworks in near future then Jersey is the way to go.Personally, I like Jersey but the power of other related Spring projects makes spring a good choice as well.





3 thoughts on “Spring Boot Jersey Example

Leave a Reply

Your email address will not be published. Required fields are marked *