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

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.

主站蜘蛛池模板: 毕节市| 平邑县| 山东省| 图们市| 宜兰县| 新疆| 留坝县| 襄樊市| 文山县| 延边| 葵青区| 凤山市| 平山县| 信丰县| 新余市| 邵阳县| 栖霞市| 丰县| 无锡市| 东台市| 合江县| 章丘市| 霍林郭勒市| 蚌埠市| 辽阳县| 嘉义县| 弥勒县| 神池县| 始兴县| 大同市| 台南县| 崇阳县| 抚顺市| 绿春县| 杭锦后旗| 黎川县| 麻城市| 延庆县| 湖州市| 旬邑县| 汉沽区|