Create a Spring Bean Using YAML

综合编程 2018-06-14 阅读原文

Spring is a highly adopted annotation-based configuration and it is happily accepted by developer communities. And why not? No one wants to struggle with XML tags, but that's not enough when there is no XML configuration or the external file configuration is not as powerful as an XML configuration would be; especially when we write an application that has to alter behaviors without compilation.

But still, writing an XML configuration is not readable and not easily understood by beginners, so I've written experimental plugins for Spring Boot that convert YAML definitions to Spring Beans.

Here is an example of a bean definition in XML and the bean definition in YAML.



    
        
            Rohit
        
        
            jain
        
        
            203428304230
        
        
    
    
        
            gyan nagar
        
        
            sector 4
        
        
            313001
        
        
            Pune
        
        
            Maharastra
        
        
    
    
        
            India
        
        
            +91
        
        
            INR
        
    
#spring-beans

customerImpl:
  class: com.example.yamlbeanExample.Customer
  properties:
    firstName: Rohit
    lastName: jain
    phone: 203428304230
    address: ref::addressImpl
addressImpl:
  class: com.example.yamlbeanExample.Address
  properties:
    address1: gyan nagar
    address2: sector 4
    pinCode: 313001
    city: pune
    state: Maharastra
    country: ref::countryImpl
countryImpl:
  class: com.example.yamlbeanExample.Country
  properties:
    countryName: India
    countryCode: 91
    currency: INR

You can check out a project on GitHub
.

Note -> YAML-spring-beans is a just experimental library, there are lots of features not included. Feedback will be much appreciated!

Javalobby

责编内容by:Javalobby阅读原文】。感谢您的支持!

您可能感兴趣的

深入浅出MyBatis:MyBatis与Spring集成及实用场景... 本系列是「深入浅出MyBatis:技术原理与实践」书籍的总结笔记。 本篇是「深入浅出MyBatis」系列的最后一篇,主要介绍与Spring的集成,以及工作中...
Mybatis学习笔记之二(动态mapper开发和spring-mybatis整合)... 一、输入映射和输出映射 1.1 parameterType(输入类型) 【传递简单类型】 详情参考 Mybatis学习笔记之一(环境搭建和入...
Moving at The Speed of Startup With Pivotal Cloud ... In the world ofmicroservices andcloud-native, customers want more than a par...
Spring AMQP 2.0.3 和 1.7.7 发布,包含大量更新... Spring AMQP 2.0.3 和 1.7.7 发布,包含大量更新。 2.0.3 更新: 6dc3228 ...
spring-messaging RCE(cve-2018-1270) 重现 0x00 概述 4月5号网上爆出spring框架的一个rce漏洞,编号cve-2018-1270,著名的ssh框架就用了spring。 漏洞存在于s...