Skip to content

Commit 0a8766e

Browse files
committed
Provide working sample for Tomcat using HTTP/2
1 parent f380489 commit 0a8766e

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

spring-boot-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<module>spring-boot-sample-tomcat</module>
8282
<module>spring-boot-sample-tomcat-jsp</module>
8383
<module>spring-boot-sample-tomcat-ssl</module>
84+
<module>spring-boot-sample-tomcat-http2</module>
8485
<module>spring-boot-sample-tomcat-multi-connectors</module>
8586
<module>spring-boot-sample-traditional</module>
8687
<module>spring-boot-sample-undertow</module>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<!-- Your own application should inherit from spring-boot-starter-parent -->
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-samples</artifactId>
8+
<version>2.0.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>spring-boot-sample-tomcat-http2</artifactId>
11+
<name>Spring Boot Tomcat HTTP/2 Sample</name>
12+
<description>Spring Boot Tomcat HTTP/2 Sample</description>
13+
<url>http://projects.spring.io/spring-boot/</url>
14+
<organization>
15+
<name>Pivotal Software, Inc.</name>
16+
<url>http://www.spring.io</url>
17+
</organization>
18+
<properties>
19+
<main.basedir>${basedir}/../..</main.basedir>
20+
</properties>
21+
<dependencies>
22+
<!-- Compile -->
23+
<dependency>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-tomcat</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework</groupId>
33+
<artifactId>spring-webmvc</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.httpcomponents</groupId>
37+
<artifactId>httpclient</artifactId>
38+
</dependency>
39+
<!-- Test -->
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-test</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.yaml</groupId>
47+
<artifactId>snakeyaml</artifactId>
48+
</dependency>
49+
</dependencies>
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2017 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.tomcat.http2;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
@SpringBootApplication
25+
@RestController
26+
public class SampleTomcatHttp2Application {
27+
28+
public static void main(String[] args) throws Exception {
29+
SpringApplication.run(SampleTomcatHttp2Application.class, args);
30+
}
31+
32+
@GetMapping("/")
33+
public String helloWorld() {
34+
return "Hello, world";
35+
}
36+
37+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
server.port = 8443
2+
server.http2.enabled = true
3+
server.ssl.key-store = classpath:sample.jks
4+
server.ssl.key-store-password = secret
5+
server.ssl.key-password = password
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-2017 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.tomcat.http2;
18+
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.http.HttpStatus;
27+
import org.springframework.http.ResponseEntity;
28+
import org.springframework.test.annotation.DirtiesContext;
29+
import org.springframework.test.context.junit4.SpringRunner;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
@RunWith(SpringRunner.class)
34+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
35+
@DirtiesContext
36+
public class SampleTomcatHttp2ApplicationTests {
37+
38+
@Autowired
39+
private TestRestTemplate restTemplate;
40+
41+
@Test
42+
public void testHome() throws Exception {
43+
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
44+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
45+
assertThat(entity.getBody()).isEqualTo("Hello, world");
46+
}
47+
48+
}

0 commit comments

Comments
 (0)