Matt Raible compares the Java web frameworks Micronaut, Quarkus, and Spring Boot for building REST APIs. He demonstrates how to quickly get started with each framework, secure APIs with OAuth 2.1 and JWTs, build Docker images, and go native with GraalVM. Performance tests show Quarkus has the fastest startup time while Spring Boot has the largest community support in areas like Stack Overflow questions, GitHub stars, and jobs on Indeed.
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Java REST API Comparison: Micronaut, Quarkus, and Spring Boot
1. Matt Raible | @mraible
September 30, 2020
Java REST API Comparison
Micronaut, Quarkus, and
Spring Boot
Photo by Matt Duncan on https://unsplash.com/photos/IUY_3DvM__w
3. @mraible
Who is Matt Raible?
Father, Husband, Skier, Mountain
Biker, Whitewater Rafter
Bus Lover
Web Developer and Java Champion
Okta Developer Advocate
Blogger on raibledesigns.com and
developer.okta.com/blog
@mraible
4.
5.
6.
7. @mraible
Today’s Agenda
Why Java?
Build { REST, GraphQL } APIs with Java
Secure your APIs with OAuth 2.1
Build with Docker
Go Native with GraalVM
https://unsplash.com/photos/JsTmUnHdVYQ
8. @mraible
Why Java?
25 Years
of use, abuse, and improvements
Open Source
code is available; many popular open source
frameworks and tools
Hugely Popular and widely used
by many enterprises and web-scale companies
9. @mraible
Download the JDK from OpenJDK
https://jdk.java.net/15
Or from AdoptOpenJDK
https://adoptopenjdk.net
Get Started with Java 15
10. @mraible
Get Started with Java 15
Better yet, use SDKMAN!
curl -s https://get.sdkman.io | bash
sdk install java 15.0.0.hs-adpt
11. What’s New in Java 15
https://blogs.oracle.com/java-platform-group/the-arrival-of-java-15
22. @mraible
Get Started with Quarkus
mvn io.quarkus:quarkus-maven-plugin:1.8.1.Final:create
-DprojectGroupId=com.okta.rest
-DprojectArtifactId=quarkus
-DclassName="com.okta.rest.quarkus.HelloResource"
-Dpath="/hello"
-Dextensions="jwt"
30. @mraible
Get Started with Spring Boot
http https://start.spring.io/starter.zip
dependencies==web,okta
packageName==com.okta.rest
name=spring-boot
type=maven-project
-o spring-boot.zip
33. Spring Security OAuth 2.0 Resource Server
https://docs.spring.io/spring-security/site/docs/5.4.0/reference/html5/#oauth2resourceserver
okta.oauth2.issuer=https://dev-133337.okta.com/
oauth2/default
34. Test Spring Boot with HTTPie
https://httpie.org
mvn spring-boot:run
http :8080/hello
TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN...
http :8080/hello Authorization:"Bearer $TOKEN"
37. @mraible
Build GraphQL APIs with Java
Why GraphQL?
Does your favorite framework support GraphQL?
Micronaut
https://micronaut-projects.github.io/micronaut-graphql/latest/guide
Quarkus
https://quarkus.io/guides/microprofile-graphql
Spring Boot
https://github.com/leangen/graphql-spqr-spring-boot-starter
38. @mraible
Secure your API with OAuth 2.0
https://aaronparecki.com/2019/12/12/21/its-time-for-oauth-2-dot-1
39. @mraible
Secure your API with OAuth 2.1
https://oauth.net/2.1
PKCE is required for all clients using the authorization code flow
Redirect URIs must be compared using exact string matching
The Implicit grant is omitted from this specification
The Resource Owner Password Credentials grant is omitted from this specification
Bearer token usage omits the use of bearer tokens in the query string of URIs
Refresh tokens for public clients must either be sender-constrained or one-time use
40. @mraible
Authenticate with OpenID Connect (OIDC)
What is OpenID Connect?
Does your favorite framework support OIDC authentication?
Micronaut
https://guides.micronaut.io/micronaut-oauth2-okta/guide
Quarkus
https://quarkus.io/guides/security-openid-connect-web-authentication
Spring Boot
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2login
42. @mraible
Build with Docker
Create a Dockerfile
FROM openjdk:15-alpine
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
43. @mraible
Build with Docker
Build your image
docker build -t <tag-name> .
Run your image
docker run -i --rm -p 8080:8080 <tag-name>
44. @mraible
Build with Docker: Jib
Get Jibby with it!
mvn verify jib:build
Or build directly to your Docker daemon
mvn verify jib:dockerBuild
https://github.com/GoogleContainerTools/jib
45. @mraible
Build with Docker
Micronaut generates a Dockerfile
Quarkus generates three Docker-related files
Dockerfile.fast-jar
Dockerfile.jvm
Dockerfile.native
Quarkus + Jib
mvn quarkus:add-extension -Dextensions="container-image-jib"
46. @mraible
Build with Docker
Spring Boot 2.3+ has built-in support
mvn spring-boot:build-image
Uses layered JARs for for faster builds
dependencies
snapshot-dependencies
resources
application
https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1
47. @mraible
Use Micronaut CLI
mn create-app ... -f graalvm
mn feature-diff --features=graalvm
mvn package
./docker-build.sh
Go Native with GraalVM and Micronaut
https://docs.micronaut.io/latest/guide/#graal
48. @mraible
Go Native with GraalVM and Quarkus
It’s built-in to Quarkus!
mvn package -Pnative -Dquarkus.native.container-build=true
Then build the image
docker build -f src/main/docker/Dockerfile.native -t <tag-
name> .
And run it
docker run -i --rm -p 8080:8080 <tag-name>
https://quarkus.io/guides/building-native-image
49. @mraible
Go Native with GraalVM and Spring Boot
Upgrade to Spring 2.4.0-M2
<version>2.4.0-M2</version>
Update configuration to avoid proxies
https://tanzu.vmware.com/content/slides/the-path-towards-spring-boot-native-applications-2
@SpringBootApplication(proxyBeanMethods = false)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
50. @mraible
Go Native with GraalVM and Spring Boot
Add Milestone repositories to your pom.xml
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
51. @mraible
Go Native with GraalVM and Spring Boot
Configure your Spring Boot Maven Plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<env>
<BP_BOOT_NATIVE_IMAGE>1</BP_BOOT_NATIVE_IMAGE>
<BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>
-Dspring.native.remove-yaml-support=true
-Dspring.spel.ignore=true
--enable-https
</BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
</image>
</configuration>
</plugin>
https://www.graalvm.org/reference-manual/native-image/JCASecurityServices/
52. @mraible
Go Native with GraalVM and Spring Boot
Add Spring GraalVM dependency
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-graalvm-native</artifactId>
<version>0.8.0</version>
</dependency>
Build the native application
mvn spring-boot:build-image
53. @mraible
Go Native with GraalVM and Spring Boot
Run your native Spring Boot app!
docker run -p 8080:8080 docker.io/library/demo:0.0.1-SNAPSHOT
💣
🐛 https://github.com/okta/okta-spring-boot/issues/192
54. @mraible
Attempted Workaround for Okta + GraalVM
Use Spring Security’s resource server
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://...