官术网_书友最值得收藏!

  • Kotlin Blueprints
  • Ashish Belagali Hardik Trivedi Akshay Chordiya
  • 96字
  • 2021-07-02 21:50:12

Functional bean declaration DSL

In Spring, we register our beans either using XML or the  @Configuration and @Bean annotations. When Spring Boot is used from Kotlin, there is a new alternative to declare the beans using lambdas, which act as FactoryBean.

Registering beans in Java:

    GenericApplicationContext context = new   
GenericApplicationContext();
context.registerBean(Message.class);

With DSL style and reified type parameters, the Kotlin equivalent is as simple and beautiful as the following:

    beans {
bean<Message>()
}

Now that we understand the key constructs of Kotlin while building Spring Boot applications, let's move on to the example application.

主站蜘蛛池模板: 怀柔区| 沙湾县| 宣城市| 大方县| 富裕县| 天镇县| 卓尼县| 怀宁县| 措勤县| 尚义县| 通城县| 镇康县| 内乡县| 青铜峡市| 汝州市| 会宁县| 舟山市| 洞口县| 林口县| 许昌市| 云阳县| 青神县| 平南县| 富宁县| 保亭| 抚顺市| 云和县| 太原市| 红原县| 武隆县| 封丘县| 康平县| 吐鲁番市| 怀远县| 灵寿县| 扎鲁特旗| 平塘县| 宜阳县| 尉犁县| 定安县| 梁山县|