技术雷达SpringBoot极简教程 · Spring Boot

Spring Fu is an incubator for ne

2018-11-05  本文已影响25人  光剑书架上的书

Spring Fu

Spring Fu is an incubator for new Spring features about Kotlin and functional bean registration. It introduces Kofu and Jafu configuration for configuring Spring Boot in a functional way, Coroutines support, GraalVM native images support and various other features.

Spring Fu is an incubator for new Spring features about Kotlin and functional bean registration. Its main feature is an alternative way of configuring Spring Boot applications with Kotlin DSL and lambdas instead of annotations: Kofu (for Kotlin and functional) configuration. Other features like Coroutines or GraalVM support are also included.

A Java variant called Jafu (for Java and functional) is also available (just a POC for now).

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. The table bellow summarize the status of current features.

Getting started

https://spring.io/blog/2018/10/02/the-evolution-of-spring-fu

Via start.spring.io

package com.example

import org.springframework.fu.kofu.application

val app = application {
    // ...
}

fun main() = app.run()



// 例如:
val app = application {
  import(beans)
  listener<ApplicationReadyEvent> {
    ref<UserRepository>().init()
  }
  properties<SampleProperties>("sample")
  server {
    port = if (profiles.contains("test")) 8181 else 8080
    mustache()
    codecs {
      string()
      jackson {
        indentOutput = true
      }
    }
    import(::routes)
  }
  mongodb {
    embedded()
  }
}

val beans = beans {
  bean<UserRepository>()
  bean<UserHandler>()
}

fun routes(userHandler: UserHandler) = router {
  GET("/", userHandler::listView)
  GET("/api/user", userHandler::listApi)
  GET("/conf", userHandler::conf)
}

fun main() = app.run()

Samples

You can also have a look to the sample applications.

Credits

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


Kotlin 开发者社区

国内第一Kotlin 开发者社区公众号,主要分享、交流 Kotlin 编程语言、Spring Boot、Android、React.js/Node.js、函数式编程、编程思想等相关主题。

开发者社区 QRCode.jpg
上一篇下一篇

猜你喜欢

热点阅读