Coder Social home page Coder Social logo

sadnessofatlantis / spring-fu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spring-projects-experimental/spring-fu

0.0 1.0 0.0 16.49 MB

Explicit configuration for Spring Boot using Kotlin and Kofu DSL

License: Apache License 2.0

Kotlin 63.31% Java 36.52% Shell 0.16% HTML 0.01%

spring-fu's Introduction

Build Status API documentation

Spring Fu is an incubator for Kofu (Ko for Kotlin, fu for functional), which provides a Kotlin API to configure Spring Boot applications programmatically with following characteristics:

  • Explicit configuration via a Kotlin DSL instead of auto-configuration

  • Leverages Spring Framework 5 functional bean configuration instead of annotations

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

  • Great discoverability via code auto-complete

  • Web functional routing instead of @Controller available in 3 flavors:

  • Persistence via Spring Data functional APIs like:

  • Configuration via Spring Security security { } DSL (WIP)

  • Fast startup and low memory consumption

It is not intended to be used in production yet, but rather to incubate and get feedback and contributions from the community in order to hopefully reach a point where it can be integrated as part of Spring Boot.

If you are interested in running Spring application as GraalVM native images see this dedicated Spring Framework issue.

Minimal application

Here is a minimal sample application that is leveraging WebMvc.fn:

val app = application(WebApplicationType.SERVLET) {
	logging {
		level = LogLevel.DEBUG
	}
	beans {
		bean<SampleService>()
	}
	webMvc {
		port = if (profiles.contains("test")) 8181 else 8080
		router {
			val service = ref<SampleService>()
			GET("/") {
				ok().body(service.generateMessage())
			}
			GET("/api") {
				ok().body(Sample(service.generateMessage()))
			}
		}
		converters {
			string()
			jackson {
				indentOutput = true
			}
		}
	}
}

data class Sample(val message: String)

class SampleService {
	fun generateMessage() = "Hello world!"
}

fun main() {
	app.run()
}

To use WebFlux.fn instead

  • Use WebApplicationType.REACTIVE instead of WebApplicationType.SERVLET

  • Use webFlux { } instead of webMvc { }

  • Use spring-boot-starter-webflux starter instead of spring-boot-starter-web

  • Use coRouter { } instead of router { } if you want to use Coroutines instead of Reactor API

Dependencies

Kofu is technically just a dependency you add to your Spring Boot project.

dependencies {
	implementation("org.springframework.fu:spring-fu-kofu:0.x")

	implementation("org.springframework.boot:spring-boot-starter-web")
	testImplementation("org.springframework.boot:spring-boot-starter-webflux")
}

Getting started

  • Create a Spring 2.2.0.M3 project on start.spring.io with the "Web" or "Reactive web" starter

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

  • Modify the generated DemoApplication.kt file as following:

package com.sample

import org.springframework.fu.kofu.application

val app = application(...) {
	...
}

fun main() {
	app.run()
}

See sample projects here.

Credits

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

spring-fu's People

Contributors

sdeleuze avatar tgirard12 avatar alek-sys avatar jnizet avatar making avatar alexczar avatar malltshik avatar t-kameyama avatar sandjelkovic avatar wpanas avatar ksvasan avatar silasmahler avatar irus avatar miguelarca avatar neversleepz avatar hauerio avatar kinmarui avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.