Skip to content

Commit 64ef03a

Browse files
author
Dave Syer
committed
Fix Jersey1 integration test
1 parent 24da6a5 commit 64ef03a

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,58 @@ upon successful completion of a servlet's service method. You should disable th
10301030
behaviour 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

spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFacto
4040
public FilterRegistrationBean jersey() {
4141
FilterRegistrationBean bean = new FilterRegistrationBean();
4242
bean.setFilter(new ServletContainer());
43-
bean.addInitParameter("com.sun.jersey.config.property.packages", "com.sun.jersey;demo");
43+
bean.addInitParameter("com.sun.jersey.config.property.packages", "com.sun.jersey;sample.jersey1");
4444
return bean;
4545
}
4646

0 commit comments

Comments
 (0)