前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Fu is an incubator for new Spring features about Kotlin and functional bean registration.

Spring Fu is an incubator for new Spring features about Kotlin and functional bean registration.

作者头像
一个会写诗的程序员
发布2018-12-06 11:31:36
6940
发布2018-12-06 11:31:36
举报
文章被收录于专栏:一个会写诗的程序员的博客

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

  • Create a Spring 2.1.x.RELEASE project on start.spring.io,
  • Add the org.springframework.fu:spring-fu-kofu:0.0.3.BUILD-SNAPSHOT dependency
  • Use Kotlin 1.3.0
  • Modify the generated *Application.kt file as following:
代码语言:javascript
复制
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:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.11.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Spring Fu
    • Getting started
      • Via start.spring.io
      • Samples
      • Credits
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档