From 8b62f448bae09be12968c868f5015387c22826fa Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 5 Nov 2019 14:17:07 +0000 Subject: [PATCH] Improve documentation on using Jersey alongside Spring MVC Previously, the documentation did not provide any guidance on using Jersey alongside Spring MVC or any other web framework. This improves the documentation in two ways: 1. It notes that, in the presence of both Jersey and Spring MVC, the Actuator will prefer Spring MVC for exposing HTTP endpoints. 2. It adds a how-to describing how to configure Jersey to forward requests for which it has no handler on to the rest of the filter chain. When Spring MVC is the other framework, this allows them to be handled by its dispatcher servlet. Closes gh-17523 --- .../src/main/asciidoc/howto.adoc | 21 +++++++++++++++++++ .../asciidoc/production-ready-features.adoc | 3 +++ 2 files changed, 24 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index 720ca2ed67b..8e093da906d 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1219,6 +1219,27 @@ include::{code-examples}/jersey/JerseySetStatusOverSendErrorExample.java[tag=res +[[howto-jersey-alongside-another-web-framework]] +=== Use Jersey Alongside Another Web Framework +To use Jersey alongside another web framework, such as Spring MVC, it should be configured so that it will allow the other framework to handle requests that it cannot handle. +First, configure Jersey to use a Filter rather than a Servlet by configuring the `spring.jersey.type` application property with a value of `filter`. +Second, configure your `ResourceConfig` to forward requests that would have resulted in a 404, as shown in the following example. + +[source,java,indent=0,subs="verbatim,quotes,attributes"] +---- + @Component + public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + register(Endpoint.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + } + + } +---- + + + [[howto-http-clients]] == HTTP Clients Spring Boot offers a number of starters that work with HTTP clients. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index 9c4a674a99c..e3bab34cdb4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -461,6 +461,7 @@ TIP: See {spring-boot-actuator-autoconfigure-module-code}/endpoint/web/CorsEndpo === Implementing Custom Endpoints If you add a `@Bean` annotated with `@Endpoint`, any methods annotated with `@ReadOperation`, `@WriteOperation`, or `@DeleteOperation` are automatically exposed over JMX and, in a web application, over HTTP as well. Endpoints can be exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux. +If both Jersey and Spring MVC are available, Spring MVC will be used. You can also write technology-specific endpoints by using `@JmxEndpoint` or `@WebEndpoint`. These endpoints are restricted to their respective technologies. @@ -512,6 +513,7 @@ Before calling an operation method, the input received via JMX or an HTTP reques [[production-ready-endpoints-custom-web]] ==== Custom Web Endpoints Operations on an `@Endpoint`, `@WebEndpoint`, or `@EndpointWebExtension` are automatically exposed over HTTP using Jersey, Spring MVC, or Spring WebFlux. +If both Jersey and Spring MVC are available, Spring MVC will be used. @@ -968,6 +970,7 @@ The default convention is to use the `id` of the endpoint with a prefix of `/act For example, `health` is exposed as `/actuator/health`. TIP: Actuator is supported natively with Spring MVC, Spring WebFlux, and Jersey. +If both Jersey and Spring MVC are available, Spring MVC will be used.