@@ -1030,7 +1030,58 @@ upon successful completion of a servlet's service method. You should disable th
10301030behaviour by setting `com.ibm.ws.webcontainer.invokeFlushAfterService` to `false`
10311031
10321032
1033+ [[boot-features-jersey]]
1034+ === JAX-RS and Jersey
1035+ If you prefer the JAX-RS programming model for REST endpoints you can use one of the
1036+ available implementations instead of Spring MVC. Jersey 1.x and Apache Celtix work
1037+ quite well out of the box if you just register their `Servlet` or `Filter` as a
1038+ `@Bean` in your application context. Jersey 2.x has some native Spring support so
1039+ we also provide autoconfiguration support for it in Spring Boot together with a
1040+ starter.
1041+
1042+ To get started with Jersey 2.x just include the `spring-boot-starter-jersey` as a dependency
1043+ and then you need one `@Bean` of type `ResourceConfig` in which you register all the
1044+ endpoints:
1045+
1046+ [source,java]
1047+ ----
1048+ @Component
1049+ public class JerseyConfig extends ResourceConfig {
1050+
1051+ public JerseyConfig() {
1052+ register(Endpoint.class);
1053+ }
1054+
1055+ }
1056+ ----
1057+
1058+ All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` etc.), e.g.
1059+
1060+ [source,java]
1061+ ----
1062+ @Component
1063+ @Path("/hello")
1064+ public class Endpoint {
1065+
1066+ @GET
1067+ public String message() {
1068+ return "Hello";
1069+ }
1070+
1071+ }
1072+ ----
1073+
1074+ Since the `Endpoint` is a Spring `@Component` its lifecycle
1075+ is managed by Spring and you can `@Autowired` dependencies and inject
1076+ external configuration with `@Value`. The Jersey servlet will be
1077+ registered and mapped to "/\*" by default. You can change the mapping
1078+ by adding `@ApplicationPath` to your `ResourceConfig`.
10331079
1080+ There is a {github-code}/spring-boot-samples/spring-boot-sample-jersey[Jersey sample] so
1081+ you can see how to set things up. There is also a {github-code}/spring-boot-samples/spring-boot-sample-jersey1[Jersey 1.x sample].
1082+ Note that in the Jersey 1.x sample that the spring-boot maven plugin has been configured to
1083+ unpack some Jersey jars so they can be scanned by the JAX-RS implementation (the sample
1084+ asks for them to be scanned in its `Filter` registration.
10341085
10351086[[boot-features-embedded-container]]
10361087=== Embedded servlet container support
0 commit comments