Spring Fu (for functional APIs) is an experimental Kotlin micro-framework based on functional configuration intended to test ideas for upcoming Spring Boot releases. It makes it easy to create fast and lightweight Spring-powered applications with functional APIs instead of annotations.
See the reference documentation for more details.
A simple Spring Fu web application rendering an HTML page and exposing a JSON HTTP endpoint looks like that:
fun main(args: Array<String>) = application {
bean<UserRepository>()
bean<UserHandler>()
webflux {
val port = if (profiles.contains("test")) 8181 else 8080
server(netty(port)) {
mustache()
codecs {
jackson()
}
router {
val userHandler = ref<UserHandler>()
GET("/", userHandler::listView)
GET("/api/user", userHandler::listApi)
}
}
}
}.run(await = true)
It leverages a subset of Spring Framework, Boot, Data and Security to provide an alternative configuration model for developing applications in Kotlin:
-
Provides a Kotlin idiomatic developer experience
-
Functional configuration via Kotlin DSL instead of annotations
-
Minimal reflection usage, no classpath scanning, no annotation processing required
-
Explicit configuration: minimal core, no conventions, no classpath detection
-
Flexible programmatic configuration: control flow like
if
, orfor
can be used to register conditionally your beans -
Run as native image with instant startup via GraalVM support
-
Coroutines allow to leverage Spring Reactive support (WebFlux, Data) with imperative programming style
-
Spring packages filtering in order to have a minimal classpath and deploy just what you need
-
Optional single language fullstack support with frontend written in Kotlin (compile to JavaScript or WebAssembly)
-
Self-sufficient opinionated documentation (Kotlin, constructor injection, functional configuration, WebFlux, Coroutines, etc.)
Please send us your feedback on the #spring
channel of Kotlin Slack. Feel free to open issues, contribute fixes or new modules via pull requests.
Spring Fu 0.0.1
is currently under active development so no release is available yet, but you have can try 0.0.1.BUILD-SNAPSHOT
builds.
A Spring Fu bootstrap is an archive containing minimal project templates designed to allow you getting started quickly and easily Spring Fu applications. To start a new project, download a bootstrap .zip
archive, extract it and follow README.adoc
instructions.
To start with Spring Fu, you can read the reference documentation.
API documentation will be available shortly.
You can have a look to the sample applications:
In addition to the whole Spring and Reactor teams, special credits to:
-
Juergen Hoeller for his support on Kotlin and the functional bean registration API
-
Arjen Poutsma for creating the WebFlux functional API
-
Thomas Girard for its spring-webflux-kotlin-dsl experiment that initially demonstrated this approach was possible
-
Konrad Kaminski for his awesome spring-kotlin-coroutine project