This document summarizes a presentation on Spring Boot revisited with KoFu and JaFu. KoFu and JaFu are new flavors of Spring Boot that use functional programming approaches. KoFu uses Kotlin and functional bean registration, while JaFu uses Java and a lambda-based infrastructure. The presentation discusses the benefits of Kotlin and Java evolutions, an overview of Spring Fu which is an incubator for KoFu and JaFu, examples of applications written in each flavor, efficiency gains from using Kotlin and KoFu, the team working on the project, and a roadmap for upcoming features including native application support and automated transformation between configurations.
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
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
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
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