SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
Spring Boot Revisited with
KoFu and JaFu
1
Audrey Neveu
Sébastien Deleuze
September 2–3, 2020
springone.io
Join https://springone.slack.com #session-spring-boot-revisited-with-kofu-and-jafu
Safe Harbor Statement
The following is intended to outline the general direction of VMware's offerings. It is intended for information
purposes only and may not be incorporated into any contract. Any information regarding pre-release of
VMware offerings, future updates or other planned modifications is subject to ongoing evaluation by
VMware and is subject to change. This information is provided without warranty or any kind, express or
implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied
upon in making purchasing decisions regarding VMware's offerings. These purchasing decisions should only
be based on features currently available. The development, release, and timing of any features or
functionality described for VMware's offerings in this presentation remain at the sole discretion of Pivotal.
Pivotal has no obligation to update forward looking information in this presentation.
2
Agenda
● Context
● Kotlin
● Java
● Spring Fu
○ KoFu
○ JaFu
● Native applications
● KoFu Petclinic demo
● The road ahead
3
Context
5
Enterprise JVM languages have evolved a lot
Kotlin Java 17 LTS
(2021)
Hidden gem in Spring Framework since 5.0:
functional bean registration
6
Huge potential
Not used widely yet
7
Why Kotlin?
Kotlin compared to alternative JVM languages
9
Kotlin compared to Java
10
Improve signal to noise ratio
11
Safety
12
Discoverability
13
Multi-platform
14
Pleasure
15
Kotlin support in Spring
Spring Kotlin
17
Create Kotlin project on start.spring.io
18
19
Spring Framework documentation in Kotlin
2
0
Dedicated tutorial
Spring Framework Kotlin support
● Kotlin extensions for idiomatic API
● Null-safety for 100% of Spring Framework API
● Immutable classes support
● Bean, Web and Security Kotlin DSLs
● Coroutines support
21
Upcoming Spring Framework 5.3 features
● Support for multiplatform Kotlin serialization
● Kotlin 1.4 support
● Better Kotlin documentation using Dokka 1.4
22
Java evolves faster
2
4
class Point {
private final int x;
private final int y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
int x() { return x; }
int y() { return y; }
public boolean equals(Object o) {
if (!(o instanceof Point)) return false;
Point other = (Point) o;
return other.x == x && other.y = y;
}
public int hashCode() {
return Objects.hash(x, y);
}
public String toString() {
return String.format("Point[x=%d, y=%d]", x, y);
}
}
record Point(int x, int y) { }
Records
2
5
But also
● Switch Expressions
● Pattern Matching for instanceof
● Sealed classes
2
6
Long term projects
● Loom: fibers, continuations and tail-calls for the JVM
● Panama: interconnecting JVM and native code
● Valhalla: advanced Java feature candidates
What is Spring Fu
Spring Fu is an incubator for a different flavor of
Spring Boot
2
8
A Functional programming flavor that is using
DSLs for configuration
2
9
3
0
2 DSLs
KoFu JaFu
31
What is the same than Spring Boot?
● https://start.spring.io
● Based on Spring Boot infrastructure
● Spring configuration for the JVM ecosystem
● Dependency management
● Starters
● Actuators
● Standalone executable JAR or container deployment
32
Conventions and automatic
configuration
Annotations-based configuration
Reflection-based infrastructure
Production ready
Explicit declaration
Functional configuration
Lambda-based infrastructure
Incubating
Spring Boot regular flavor Spring Fu flavor
Our goal is cheaper hosting of your Spring Boot applicationsWhat changes?
3
2
33
Spring Boot Java application
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@RestController
public class DemoController {
@GetMapping("/")
public String hello() {
return "hello";
}
@GetMapping("/api")
public Sample json() {
return new Sample("hello");
}
}
34
Spring Boot Kotlin application
@SpringBootApplication
class Application
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class DemoController {
@GetMapping("/")
fun hello() = "hello"
@GetMapping("/api")
fun json() = Sample("hello")
}
3
5
JaFu flavor
public class Application {
public static JafuApplication app = webApplication(a ->
a.beans(b -> b
.bean(Handler.class))
.enable(webMvc(s -> s
.router(r -> {
Handler h = s.ref(Handler.class);
r.GET("/", h::hello);
r.GET("/api", h::json);
}).converters(c -> c
.string()
.jackson()))));
public static void main (String[] args) {
app.run(args);
}
}
public class Handler {
public ServerResponse hello(ServerRequest r) {
return ok().body("foo");
}
public ServerResponse json(ServerRequest r) {
return ok().body(new Sample("foo"));
}
}
3
6
KoFu flavor
val app = webApplication {
beans {
bean<SampleHandler>()
}
webMvc {
router {
val handler = ref<SampleHandler>()
GET("/", handler::hello)
GET("/api", handler::json)
}
converters {
string()
jackson()
}
}
}
fun main() {
app.run()
}
class SampleHandler {
fun hello(request: ServerRequest) =
ok().body("hello")
fun json(request: ServerRequest) =
ok().body(Sample("hello"))
}
37
Spring Fu 0.4.0 scope
● Web
○ Server: Spring MVC and WebFlux
○ Client: WebClient
○ CORS
○ Jackson
○ Thymeleaf and Mustache
● Data
○ SQL: JDBC and R2DBC
○ NoSQL: Redis, Cassandra and MongoDB
● Common: configuration, logging, beans, listeners
38
Efficiency on the JVM
Sample JVM
Petclinic in Java
with annotations
Memory(RSS): 398M
Startup time: 2.6s
Petclinic in Kotlin
with KoFu
Memory(RSS): 298M
Startup time: 1.6s
3
9
Team
Sébastien Deleuze
Lead
Audrey Neveu
KoFu
Arjen Poutsma
JaFu
François
Teychene
KoFu
Native applications
41
Native ahead-of-time compilation
Java or Kotlin
application
GraalVM native
compiler
Native
executable
Lightweight
container image
EXE0110
41
Two main benefits
4
2
Instant startup
Reduced memory
consumption
JVM and native executables trade-offs
43
44
Efficiency
Sample JVM Native application
Petclinic in Java
with annotations
Memory(RSS): 398M
Startup time: 2.6s
Memory(RSS): 102M
Startup time: 0.08s
Petclinic in Kotlin
with KoFu
Memory(RSS): 298M
Startup time: 1.6s
Memory(RSS): 81M
Startup time: 0.08s
KoFu Petclinic
46
Kofu PetClinic
The road ahead
Roadmap
48
4
9
spring-fu 0.4.1 (September 2020)
5
0
spring-fu 0.5.0 (November 2020)
● Upgrade to Spring Boot 2.4.0
● Spring Security support
● Native application on lightweight container by default
JaFu will use Java 15/16/17 asap support by
GraalVM native
51
5
2
Strategy for the next steps
Spring Boot
as single
source of truth
KoFu
JaFu
Automated
transformation
Functional configuration
5
3
Comparing annotation and functional bean definition
@Configuration
public class SampleConfiguration {
@Bean
public Foo foo() {
return new Foo();
}
@Bean
public Bar bar(Foo foo) {
return new Bar(foo);
}
}
54
public class SampleInitializer implements
ApplicationContextInitializer<GenericApplicationContext> {
@Override
public void initialize(GenericApplicationContext ctx) {
ctx.registerBean(Foo.class, () -> new Foo());
ctx.registerBean(Bar.class,
() -> new Bar(ctx.getBean(Foo.class)));
}
}
5
5
spring-fu 0.6.0: automatic generation of
functional configuration
Automated
transformation
from @Configuration
to functional
configuration
with spring-init
56
spring-init
57
spring-fu 0.7.0: DSLs generation based on Spring
Boot properties
@ConfigurationProperties(prefix = "spring.r2dbc")
public class R2dbcProperties {
/**
* Database name.
*/
private String name;
/**
* Whether to generate a random database name.
*/
private boolean generateUniqueName;
}
class R2dbcDsl(private val init: R2dbcDsl.() ->
Unit) : AbstractDsl() {
/**
* Database name.
*/
var name: String? = null
/**
* Whether to generate a random database name.
*/
var generateUniqueName: Boolean = false
}
Automated
transformation
API generation is a big challenge but with
high rewards: quality, maintainability, scope.
5
8
https://github.com/spring-projects-experimental/spring-fu
https://spring.io/blog
@Audrey_Neveu and @sdeleuze on
#springone@SpringOne
Stay Connected.

Contenu connexe

Tendances

Tendances (20)

Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
DevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on KubernetesDevoxxUK: Optimizating Application Performance on Kubernetes
DevoxxUK: Optimizating Application Performance on Kubernetes
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
Orchestrating Redis & K8s Operators
Orchestrating Redis & K8s OperatorsOrchestrating Redis & K8s Operators
Orchestrating Redis & K8s Operators
 
DevNet Associate : Python introduction
DevNet Associate : Python introductionDevNet Associate : Python introduction
DevNet Associate : Python introduction
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Dropwizard Internals
Dropwizard InternalsDropwizard Internals
Dropwizard Internals
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Beyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in KubernetesBeyond Ingresses - Better Traffic Management in Kubernetes
Beyond Ingresses - Better Traffic Management in Kubernetes
 
Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
Aura Framework Overview
Aura Framework OverviewAura Framework Overview
Aura Framework Overview
 
GlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium ParisGlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium Paris
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
JAX-RS 2.1 Reloaded @ Devoxx
JAX-RS 2.1 Reloaded @ DevoxxJAX-RS 2.1 Reloaded @ Devoxx
JAX-RS 2.1 Reloaded @ Devoxx
 
a Running Tour of Cloud Foundry
a Running Tour of Cloud Foundrya Running Tour of Cloud Foundry
a Running Tour of Cloud Foundry
 
Discuss about java 9 with latest features
Discuss about java 9 with latest featuresDiscuss about java 9 with latest features
Discuss about java 9 with latest features
 

Similaire à Spring Boot Revisited with KoFu and JaFu

Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Paul King
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
intelliyole
 

Similaire à Spring Boot Revisited with KoFu and JaFu (20)

Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Introducing Spring Framework 5.3
Introducing Spring Framework 5.3Introducing Spring Framework 5.3
Introducing Spring Framework 5.3
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Loom and concurrency latest
Loom and concurrency latestLoom and concurrency latest
Loom and concurrency latest
 
2015 Java update and roadmap, JUG sevilla
2015  Java update and roadmap, JUG sevilla2015  Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
 
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO ExtendedJetpack, with new features in 2021 GDG Georgetown IO Extended
Jetpack, with new features in 2021 GDG Georgetown IO Extended
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
 
Pure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools RacePure Java RAD and Scaffolding Tools Race
Pure Java RAD and Scaffolding Tools Race
 
"Quantum" Performance Effects
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance Effects
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Smoothing Your Java with DSLs
Smoothing Your Java with DSLsSmoothing Your Java with DSLs
Smoothing Your Java with DSLs
 
1- java
1- java1- java
1- java
 
Vert.x - Reactive & Distributed [Devoxx version]
Vert.x - Reactive & Distributed [Devoxx version]Vert.x - Reactive & Distributed [Devoxx version]
Vert.x - Reactive & Distributed [Devoxx version]
 

Plus de VMware Tanzu

Plus de VMware Tanzu (20)

What AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About ItWhat AI Means For Your Product Strategy And What To Do About It
What AI Means For Your Product Strategy And What To Do About It
 
Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023Make the Right Thing the Obvious Thing at Cardinal Health 2023
Make the Right Thing the Obvious Thing at Cardinal Health 2023
 
Enhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at ScaleEnhancing DevEx and Simplifying Operations at Scale
Enhancing DevEx and Simplifying Operations at Scale
 
Spring Update | July 2023
Spring Update | July 2023Spring Update | July 2023
Spring Update | July 2023
 
Platforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a ProductPlatforms, Platform Engineering, & Platform as a Product
Platforms, Platform Engineering, & Platform as a Product
 
Building Cloud Ready Apps
Building Cloud Ready AppsBuilding Cloud Ready Apps
Building Cloud Ready Apps
 
Spring Boot 3 And Beyond
Spring Boot 3 And BeyondSpring Boot 3 And Beyond
Spring Boot 3 And Beyond
 
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdfSpring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
Spring Cloud Gateway - SpringOne Tour 2023 Charles Schwab.pdf
 
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
Simplify and Scale Enterprise Apps in the Cloud | Boston 2023
 
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
Simplify and Scale Enterprise Apps in the Cloud | Seattle 2023
 
tanzu_developer_connect.pptx
tanzu_developer_connect.pptxtanzu_developer_connect.pptx
tanzu_developer_connect.pptx
 
Tanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - FrenchTanzu Virtual Developer Connect Workshop - French
Tanzu Virtual Developer Connect Workshop - French
 
Tanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - EnglishTanzu Developer Connect Workshop - English
Tanzu Developer Connect Workshop - English
 
Virtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - EnglishVirtual Developer Connect Workshop - English
Virtual Developer Connect Workshop - English
 
Tanzu Developer Connect - French
Tanzu Developer Connect - FrenchTanzu Developer Connect - French
Tanzu Developer Connect - French
 
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
Simplify and Scale Enterprise Apps in the Cloud | Dallas 2023
 
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring BootSpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
SpringOne Tour: Deliver 15-Factor Applications on Kubernetes with Spring Boot
 
SpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software EngineerSpringOne Tour: The Influential Software Engineer
SpringOne Tour: The Influential Software Engineer
 
SpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs PracticeSpringOne Tour: Domain-Driven Design: Theory vs Practice
SpringOne Tour: Domain-Driven Design: Theory vs Practice
 
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense SolutionsSpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
SpringOne Tour: Spring Recipes: A Collection of Common-Sense Solutions
 

Dernier

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Spring Boot Revisited with KoFu and JaFu

  • 1. Spring Boot Revisited with KoFu and JaFu 1 Audrey Neveu Sébastien Deleuze September 2–3, 2020 springone.io Join https://springone.slack.com #session-spring-boot-revisited-with-kofu-and-jafu
  • 2. Safe Harbor Statement The following is intended to outline the general direction of VMware's offerings. It is intended for information purposes only and may not be incorporated into any contract. Any information regarding pre-release of VMware offerings, future updates or other planned modifications is subject to ongoing evaluation by VMware and is subject to change. This information is provided without warranty or any kind, express or implied, and is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions regarding VMware's offerings. These purchasing decisions should only be based on features currently available. The development, release, and timing of any features or functionality described for VMware's offerings in this presentation remain at the sole discretion of Pivotal. Pivotal has no obligation to update forward looking information in this presentation. 2
  • 3. Agenda ● Context ● Kotlin ● Java ● Spring Fu ○ KoFu ○ JaFu ● Native applications ● KoFu Petclinic demo ● The road ahead 3
  • 5. 5 Enterprise JVM languages have evolved a lot Kotlin Java 17 LTS (2021)
  • 6. Hidden gem in Spring Framework since 5.0: functional bean registration 6
  • 7. Huge potential Not used widely yet 7
  • 9. Kotlin compared to alternative JVM languages 9
  • 11. Improve signal to noise ratio 11
  • 18. Create Kotlin project on start.spring.io 18
  • 21. Spring Framework Kotlin support ● Kotlin extensions for idiomatic API ● Null-safety for 100% of Spring Framework API ● Immutable classes support ● Bean, Web and Security Kotlin DSLs ● Coroutines support 21
  • 22. Upcoming Spring Framework 5.3 features ● Support for multiplatform Kotlin serialization ● Kotlin 1.4 support ● Better Kotlin documentation using Dokka 1.4 22
  • 24. 2 4 class Point { private final int x; private final int y; Point(int x, int y) { this.x = x; this.y = y; } int x() { return x; } int y() { return y; } public boolean equals(Object o) { if (!(o instanceof Point)) return false; Point other = (Point) o; return other.x == x && other.y = y; } public int hashCode() { return Objects.hash(x, y); } public String toString() { return String.format("Point[x=%d, y=%d]", x, y); } } record Point(int x, int y) { } Records
  • 25. 2 5 But also ● Switch Expressions ● Pattern Matching for instanceof ● Sealed classes
  • 26. 2 6 Long term projects ● Loom: fibers, continuations and tail-calls for the JVM ● Panama: interconnecting JVM and native code ● Valhalla: advanced Java feature candidates
  • 28. Spring Fu is an incubator for a different flavor of Spring Boot 2 8
  • 29. A Functional programming flavor that is using DSLs for configuration 2 9
  • 31. 31 What is the same than Spring Boot? ● https://start.spring.io ● Based on Spring Boot infrastructure ● Spring configuration for the JVM ecosystem ● Dependency management ● Starters ● Actuators ● Standalone executable JAR or container deployment
  • 32. 32 Conventions and automatic configuration Annotations-based configuration Reflection-based infrastructure Production ready Explicit declaration Functional configuration Lambda-based infrastructure Incubating Spring Boot regular flavor Spring Fu flavor Our goal is cheaper hosting of your Spring Boot applicationsWhat changes? 3 2
  • 33. 33 Spring Boot Java application @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } @RestController public class DemoController { @GetMapping("/") public String hello() { return "hello"; } @GetMapping("/api") public Sample json() { return new Sample("hello"); } }
  • 34. 34 Spring Boot Kotlin application @SpringBootApplication class Application fun main(args: Array<String>) { runApplication<DemoApplication>(*args) } @RestController class DemoController { @GetMapping("/") fun hello() = "hello" @GetMapping("/api") fun json() = Sample("hello") }
  • 35. 3 5 JaFu flavor public class Application { public static JafuApplication app = webApplication(a -> a.beans(b -> b .bean(Handler.class)) .enable(webMvc(s -> s .router(r -> { Handler h = s.ref(Handler.class); r.GET("/", h::hello); r.GET("/api", h::json); }).converters(c -> c .string() .jackson())))); public static void main (String[] args) { app.run(args); } } public class Handler { public ServerResponse hello(ServerRequest r) { return ok().body("foo"); } public ServerResponse json(ServerRequest r) { return ok().body(new Sample("foo")); } }
  • 36. 3 6 KoFu flavor val app = webApplication { beans { bean<SampleHandler>() } webMvc { router { val handler = ref<SampleHandler>() GET("/", handler::hello) GET("/api", handler::json) } converters { string() jackson() } } } fun main() { app.run() } class SampleHandler { fun hello(request: ServerRequest) = ok().body("hello") fun json(request: ServerRequest) = ok().body(Sample("hello")) }
  • 37. 37 Spring Fu 0.4.0 scope ● Web ○ Server: Spring MVC and WebFlux ○ Client: WebClient ○ CORS ○ Jackson ○ Thymeleaf and Mustache ● Data ○ SQL: JDBC and R2DBC ○ NoSQL: Redis, Cassandra and MongoDB ● Common: configuration, logging, beans, listeners
  • 38. 38 Efficiency on the JVM Sample JVM Petclinic in Java with annotations Memory(RSS): 398M Startup time: 2.6s Petclinic in Kotlin with KoFu Memory(RSS): 298M Startup time: 1.6s
  • 39. 3 9 Team Sébastien Deleuze Lead Audrey Neveu KoFu Arjen Poutsma JaFu François Teychene KoFu
  • 41. 41 Native ahead-of-time compilation Java or Kotlin application GraalVM native compiler Native executable Lightweight container image EXE0110 41
  • 42. Two main benefits 4 2 Instant startup Reduced memory consumption
  • 43. JVM and native executables trade-offs 43
  • 44. 44 Efficiency Sample JVM Native application Petclinic in Java with annotations Memory(RSS): 398M Startup time: 2.6s Memory(RSS): 102M Startup time: 0.08s Petclinic in Kotlin with KoFu Memory(RSS): 298M Startup time: 1.6s Memory(RSS): 81M Startup time: 0.08s
  • 50. 5 0 spring-fu 0.5.0 (November 2020) ● Upgrade to Spring Boot 2.4.0 ● Spring Security support ● Native application on lightweight container by default
  • 51. JaFu will use Java 15/16/17 asap support by GraalVM native 51
  • 52. 5 2 Strategy for the next steps Spring Boot as single source of truth KoFu JaFu Automated transformation
  • 54. Comparing annotation and functional bean definition @Configuration public class SampleConfiguration { @Bean public Foo foo() { return new Foo(); } @Bean public Bar bar(Foo foo) { return new Bar(foo); } } 54 public class SampleInitializer implements ApplicationContextInitializer<GenericApplicationContext> { @Override public void initialize(GenericApplicationContext ctx) { ctx.registerBean(Foo.class, () -> new Foo()); ctx.registerBean(Bar.class, () -> new Bar(ctx.getBean(Foo.class))); } }
  • 55. 5 5 spring-fu 0.6.0: automatic generation of functional configuration Automated transformation from @Configuration to functional configuration with spring-init
  • 57. 57 spring-fu 0.7.0: DSLs generation based on Spring Boot properties @ConfigurationProperties(prefix = "spring.r2dbc") public class R2dbcProperties { /** * Database name. */ private String name; /** * Whether to generate a random database name. */ private boolean generateUniqueName; } class R2dbcDsl(private val init: R2dbcDsl.() -> Unit) : AbstractDsl() { /** * Database name. */ var name: String? = null /** * Whether to generate a random database name. */ var generateUniqueName: Boolean = false } Automated transformation
  • 58. API generation is a big challenge but with high rewards: quality, maintainability, scope. 5 8