By alx: May 2020
Spring boot with jersey
Goal
This article is about how to create and configure a Spring Boot JAX-RS 2.0 REST API with Jersey framework.Used technologies
Java 11curl 7.66
Maven 3.x Go to Spring Initializr and create a demo maven project as following:
Click Generate and pick up the downloaded zip file. Extract the zip file and import the demo into your preferred IDE.
Maven dependencies
The JAX-RS Resource
The@Path
annotation identifies the URI path template to which the resource will be accessible.
@GET
annotation indenticates that hello()
method will process HTTP GET requests.
The@Produces("text/plain")annotation is used to specify the MIME media types of the response that will be send back.
Jersey Configuration
With Spring@Component
Annotation the class will be automatically detected
Extending
ResourceConfig
to register the HelloWorldResource class
Project structure
spring-boot-jaxrs-jersey/
|-- src/
| |-- main/
| | |-- java/
| | | |-- com.wstutorial.springboot.jersey/
| | | | |-- SpringBootJaxrsJerseyApplication.java
| | | | |-- HelloWorldResource.java
| | | | |-- JerseyConfig.java
| |-- test/
| | |-- java/
| | | |-- com.wstutorial.springboot.jersey/
| | | | |-- SpringBootJaxrsJerseyApplicationTests.java
|-- mvnw
|-- mvnw.cmd
|-- pom.xml
Run the application
Let's test
The complete code can be found in GitHub