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

  • 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.

主站蜘蛛池模板: 威远县| 蓝山县| 津市市| 达州市| 蒲江县| 桂林市| 石渠县| 扬中市| 曲沃县| 万载县| 麟游县| 朝阳市| 石屏县| 富川| 奉新县| 吉首市| 永顺县| 五指山市| 根河市| 稷山县| 河东区| 于田县| 西盟| 盈江县| 华亭县| 万荣县| 湘阴县| 林甸县| 汾西县| 永善县| 内江市| 海盐县| 高邑县| 施秉县| 江阴市| 曲阳县| 峨眉山市| 武强县| 苍溪县| 肥乡县| 五华县|