Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
64ef03aa
Commit
64ef03aa
authored
Oct 02, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Jersey1 integration test
parent
24da6a50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+51
-0
SampleJersey1Application.java
...rc/main/java/sample/jersey1/SampleJersey1Application.java
+1
-1
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
64ef03aa
...
@@ -1030,7 +1030,58 @@ upon successful completion of a servlet's service method. You should disable th
...
@@ -1030,7 +1030,58 @@ upon successful completion of a servlet's service method. You should disable th
behaviour by setting `com.ibm.ws.webcontainer.invokeFlushAfterService` to `false`
behaviour by setting `com.ibm.ws.webcontainer.invokeFlushAfterService` to `false`
[[boot-features-jersey]]
=== JAX-RS and Jersey
If you prefer the JAX-RS programming model for REST endpoints you can use one of the
available implementations instead of Spring MVC. Jersey 1.x and Apache Celtix work
quite well out of the box if you just register their `Servlet` or `Filter` as a
`@Bean` in your application context. Jersey 2.x has some native Spring support so
we also provide autoconfiguration support for it in Spring Boot together with a
starter.
To get started with Jersey 2.x just include the `spring-boot-starter-jersey` as a dependency
and then you need one `@Bean` of type `ResourceConfig` in which you register all the
endpoints:
[source,java]
----
@Component
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(Endpoint.class);
}
}
----
All the registered endpoints should be `@Components` with HTTP resource annotations (`@GET` etc.), e.g.
[source,java]
----
@Component
@Path("/hello")
public class Endpoint {
@GET
public String message() {
return "Hello";
}
}
----
Since the `Endpoint` is a Spring `@Component` its lifecycle
is managed by Spring and you can `@Autowired` dependencies and inject
external configuration with `@Value`. The Jersey servlet will be
registered and mapped to "/\*" by default. You can change the mapping
by adding `@ApplicationPath` to your `ResourceConfig`.
There is a {github-code}/spring-boot-samples/spring-boot-sample-jersey[Jersey sample] so
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].
Note that in the Jersey 1.x sample that the spring-boot maven plugin has been configured to
unpack some Jersey jars so they can be scanned by the JAX-RS implementation (the sample
asks for them to be scanned in its `Filter` registration.
[[boot-features-embedded-container]]
[[boot-features-embedded-container]]
=== Embedded servlet container support
=== Embedded servlet container support
...
...
spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java
View file @
64ef03aa
...
@@ -40,7 +40,7 @@ public class SampleJersey1Application {
...
@@ -40,7 +40,7 @@ public class SampleJersey1Application {
public
FilterRegistrationBean
jersey
()
{
public
FilterRegistrationBean
jersey
()
{
FilterRegistrationBean
bean
=
new
FilterRegistrationBean
();
FilterRegistrationBean
bean
=
new
FilterRegistrationBean
();
bean
.
setFilter
(
new
ServletContainer
());
bean
.
setFilter
(
new
ServletContainer
());
bean
.
addInitParameter
(
"com.sun.jersey.config.property.packages"
,
"com.sun.jersey;
demo
"
);
bean
.
addInitParameter
(
"com.sun.jersey.config.property.packages"
,
"com.sun.jersey;
sample.jersey1
"
);
return
bean
;
return
bean
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment