Using RESTEasy Spring Boot starter integration. This is not just builtin Jersey integration!
pom.xml
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring-boot-starter</artifactId>
<version>4.5.1.Final</version>
</dependency>
app
@SpringBootApplication
public class RESTEasySpringBootApplication {
@Component
@ApplicationPath("/api")
public static class RESTEasyConfig extends Application {
@Component
@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
public static class RESTEasyResource {
@GET
public Map<String, String> hello() {
return Map.of("message", "Hello, World!");
}
}
}
public static void main(String[] args) {
SpringApplication.run(RESTEasySpringBootApplication.class, args);
}
}
tests
@SpringBootTest
class RESTEasySpringBootApplicationTests {
@Autowired
WebTestClient webTestClient;
@Test
void contextLoads() {
webTestClient.get()
.uri("/api/hello")
.exchange()
.expectStatus().isOk()
.expectBody(new ParameterizedTypeReference<Map<String, String>>() {})
.consumeWith(mapEntityExchangeResult -> {
var map = mapEntityExchangeResult.getResponseBody();
assertThat(map.get("message")).isNotNull()
.isEqualToIgnoringCase("hello, world!");
});
}
}
or simply
./mvnw spring-boot:run
http :8080/api/hello