Skip to content

Enable HTTP 2.0 in spring-boot 2 non netty (non webflux) apps running on java 9+

License

Notifications You must be signed in to change notification settings

daggerok/spring-boot-http2

Repository files navigation

spring-boot-http2 Build Status

HTTP 2.0 with spring-boot 2 on java 9+

TL;DR

Example how to enable HTTP 2.0 in spring-boot 2 non netty (non webflux) apps running on java 9+

certificate

generate self signed sertificates
# server side:
keytool -genkeypair -alias my-keystore -keyalg RSA -keystore src/main/resources/my-keystore.jks \
        -dname "CN=boot-jwt, L=Odessa, S=Odessa, C=UA" \
        -keypass my-keystore-password -storepass my-keystore-password

keytool -list -rfc --keystore src/main/resources/my-keystore.jks | openssl x509 -inform pem -pubkey > src/main/resources/my-keystore.pem
Enter keystore password:  my-keystore-password

# client side:
openssl x509 -pubkey -noout -in src/main/resources/my-keystore.pem  > src/main/resources/my-keystore-pubkey.pem

so now we have it: - server will consume file: src/main/resources/my-keystore.jks - clients needs file: src/main/resources/my-keystore-pubkey.pem

setup spring-boot app

output
link:./src/main/resources/application.yaml[role=include]

install java 9 or 10 or use jenv to switch java version

http 2.0 is working on java 9+, so lets switch on it:
# install jenv to easily switch between java verions:
brew install jenv

# install java 9

# all installed JVMs on my mac:
ls -l /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x  3 root  wheel  96 Jul 15  2015 1.6.0.jdk
drwxr-xr-x  3 root  wheel  96 Apr 20 22:42 jdk-10.0.1.jdk
drwxr-xr-x  2 root  wheel  64 Apr 20 22:42 jdk-10.jdk
drwxr-xr-x  3 root  wheel  96 Nov  8  2017 jdk-9.0.1.jdk
drwxr-xr-x  2 root  wheel  64 Mar 24 04:08 jdk-9.0.4.jdk
drwxr-xr-x  3 root  wheel  96 Mar 28 00:34 jdk1.7.0_80.jdk
drwxr-xr-x  3 root  wheel  96 Nov 11  2017 jdk1.8.0_152.jdk
drwxr-xr-x  3 root  wheel  96 Mar 19 01:59 jdk1.8.0_161.jdk
drwxr-xr-x  2 root  wheel  64 Apr 20 22:44 jdk1.8.0_162.jdk
drwxr-xr-x  3 root  wheel  96 Apr 20 22:44 jdk1.8.0_172.jdk

# add JVM 9 to my jenv:
jenv add /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/
oracle64-9.0.1 added
9.0 added

# check current JVM:
java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

# check avalible JVMs to switch to:
jenv versions
  system
  1.6
  1.6.0.65
  1.7
  1.7.0.80
  1.8
  1.8.0.152
  10.0
  10.0.1
  9.0
  9.0.1
  oracle64-1.6.0.65
  oracle64-1.7.0.80
* oracle64-1.8.0.152 (set by /private/tmp/spring-boot-http2/.java-version)
  oracle64-10.0.1
  oracle64-9.0.1

# switch local jvm to JDK 9:
jenv local 9.0.1

# versify:
java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
now build and run project using gradle:
./gradlew clean build
bash ./build/libs/*.jar
switch to java 10 and build using maven:
jenv local 10.0

java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

./mvnw

bash target/*.jar

Lastly open browser https://127.0.0.1:8443/ and developer tool and refresh page. Go to network tab and enable protocol column. Refresh page and if you can see: h2 protocol, then everything is correct

generated by generator-jvm yeoman generator (java-spring-boot)

About

Enable HTTP 2.0 in spring-boot 2 non netty (non webflux) apps running on java 9+

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published