Skip to content

feilfeilundfeil/spring-fu

 
 

Repository files navigation

Spring Fu

Build Status

Spring Fu is an incubator for features related to Kotlin, explicit configuration and runtime efficiency.

Its main incubating feature is Kofu, which provides any API to configure Spring Boot applications in an explicit way. Instead of leveraging auto-configuration and annotations, Kofu provides a nice application { } DSL to configure Spring Boot explicitly and efficiently with great discoverability via auto-complete in the IDE.

It has following characteristics:

  • Explicit configuration via Kotlin DSL instead of auto-configuration

  • Allows to define custom configuration slices (useful for more focused and efficient testing)

  • Minimal set of features enabled by default

  • Functional configuration based on pure lambdas instead of annotations

  • Great discoverability via code auto-complete

  • Both declarative and programmatic (allow any kind of if, for statements)

  • Minimal reflection usage, no CGLIB proxy, no annotation processing

  • Fast startup and low memory consumption

  • Lazy loading of beans enabled by default

  • Spring MVC (WIP) and WebFlux support via router DSLs instead of @Controller

  • Coroutines allows to leverage Spring reactive stack in a more imperative way

  • GraalVM native image friendly

It is not intended to be used in production, but rather to incubate and get feedback and contributions from the community in order to reach a point where its features can be integrated as part of existing Spring projects like Framework, Boot and Data.

API reference

An overview of Kofu DSL is provided bellow with the related API documentation.

val dataConfig = configuration { (1)
	beans { } (2)
	mongodb { } (3)
	r2dbcH2 { } (4)
	r2dbcPostgresql {} (5)
}

val webConfig = configuration { (1)
	beans { } (2)
	webFlux { (6)
		engine = (7)
		port = (8)
		router { } (9)
		include() (10)
		coRouter { } (11)
		cors { } (12)
		codecs { } (13)
		mustache() (14)
		filter() (15)
	}
	webClient { (16)
		baseUrl = (17)
		codecs { } (18)
	}
}

val app = application(WebApplicationType.REACTIVE) { (19)
	logging { } (20)
	configurationProperties<SampleProperties>() (21)
	listener<SampleEvent> { } (22)
	profile("sample"){ } (23)
	enable(dataConfig) (24)
	enable(webConfig) (24)
}

fun main() {
	app.run() (25)
}

Getting started

  • Create a Spring 2.2.x project on start.spring.io with the "Reactive web" starter

  • Add the Spring milestone repository https://repo.spring.io/milestone

  • Add the org.springframework.fu:spring-fu-kofu:0.0.5 dependency

  • Use latest Kotlin 1.3.x

  • Modify the generated DemoApplication.kt file as following:

package com.sample

import org.springframework.fu.kofu.application

val app = application(WebApplicationType.REACTIVE) {
	webFlux {
		router {
			GET("/") { ok().syncBody("Hello world!") }
		}
	}
}

fun main() {
	app.run()
}

Samples

kofu-reactive-minimal

This is a sample project for a Spring Boot Reactive web application with Kofu configuration which provides a http://localhost:8080/ endpoint that displays "Hello world!" and an http://localhost:8080/api with a JSON endpoint.

You can run compile and run it as a Graal native image (GraalVM 1.0 RC10+) by running ./build.sh then ./com.sample.applicationkt.

kofu-reactive-mongodb

This is a sample project for a Spring Boot Reactive web application with Kofu configuration and a Reactive MongoDB backend.

kofu-reactive-r2dbc

This is a sample project for a Spring Boot Reactive web application with Kofu configuration and a R2DBC backend.

kofu-coroutines-mongodb

This is a sample project for a Spring Boot Coroutines web application with Kofu configuration and a Reactive MongoDB backend.

kofu-coroutines-r2dbc

This is a sample project for a Spring Boot Coroutines web application with Kofu configuration and a R2DBC backend.

Credits

In addition to the whole Spring and Reactor teams, special credits to:

About

Spring Fu is an incubator for features related to Kotlin, explicit configuration and runtime efficiency.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 66.2%
  • Java 33.5%
  • Other 0.3%