Skip to content

Commit 492cf4e

Browse files
committed
Add jersey-bean-validation to spring-boot-starter-jersey
A dependency on org.glassfish.jersey.ext:jersey-bean-validation has been added to spring-boot-starter-jersey. jersey-bean-validation’s EL dependencies have been excluded in favour of those provided by spring-boot-starter-tomcat (or starter-jetty or starter-undertow should the user choose to use a different embedded container). Closes gh-2315
1 parent 16cb44f commit 492cf4e

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

spring-boot-dependencies/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,11 @@
10531053
<artifactId>jersey-server</artifactId>
10541054
<version>${jersey.version}</version>
10551055
</dependency>
1056+
<dependency>
1057+
<groupId>org.glassfish.jersey.ext</groupId>
1058+
<artifactId>jersey-bean-validation</artifactId>
1059+
<version>${jersey.version}</version>
1060+
</dependency>
10561061
<dependency>
10571062
<groupId>org.glassfish.jersey.ext</groupId>
10581063
<artifactId>jersey-spring3</artifactId>

spring-boot-samples/spring-boot-sample-jersey/src/main/java/sample/jersey/JerseyConfig.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ public class JerseyConfig extends ResourceConfig {
2424

2525
public JerseyConfig() {
2626
register(Endpoint.class);
27+
register(ReverseEndpoint.class);
2728
}
2829

2930
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.jersey;
18+
19+
import javax.validation.constraints.NotNull;
20+
import javax.ws.rs.GET;
21+
import javax.ws.rs.Path;
22+
import javax.ws.rs.QueryParam;
23+
24+
import org.springframework.stereotype.Component;
25+
26+
@Component
27+
@Path("/reverse")
28+
public class ReverseEndpoint {
29+
30+
@GET
31+
public String reverse(@QueryParam("input") @NotNull String input) {
32+
return new StringBuilder(input).reverse().toString();
33+
}
34+
35+
}

spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,4 +48,19 @@ public void contextLoads() {
4848
assertEquals(HttpStatus.OK, entity.getStatusCode());
4949
}
5050

51+
@Test
52+
public void reverse() {
53+
ResponseEntity<String> entity = this.restTemplate.getForEntity(
54+
"http://localhost:" + this.port + "/reverse?input=olleh", String.class);
55+
assertEquals(HttpStatus.OK, entity.getStatusCode());
56+
assertEquals("hello", entity.getBody());
57+
}
58+
59+
@Test
60+
public void validation() {
61+
ResponseEntity<String> entity = this.restTemplate.getForEntity(
62+
"http://localhost:" + this.port + "/reverse", String.class);
63+
assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode());
64+
}
65+
5166
}

spring-boot-starters/spring-boot-starter-jersey/pom.xml

+14
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@
6060
<groupId>org.glassfish.jersey.containers</groupId>
6161
<artifactId>jersey-container-servlet</artifactId>
6262
</dependency>
63+
<dependency>
64+
<groupId>org.glassfish.jersey.ext</groupId>
65+
<artifactId>jersey-bean-validation</artifactId>
66+
<exclusions>
67+
<exclusion>
68+
<groupId>javax.el</groupId>
69+
<artifactId>javax.el-api</artifactId>
70+
</exclusion>
71+
<exclusion>
72+
<groupId>org.glassfish.web</groupId>
73+
<artifactId>javax.el</artifactId>
74+
</exclusion>
75+
</exclusions>
76+
</dependency>
6377
<dependency>
6478
<groupId>org.glassfish.jersey.ext</groupId>
6579
<artifactId>jersey-spring3</artifactId>

0 commit comments

Comments
 (0)