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!

您可能感兴趣的

实体服务是一种反模式 在微服务架构中,最重要的是要保持服务间的隔离。实体服务(Entity Service)是被广泛应用于微服务架构上的一种模式,但其实它是一种 反模式 ,因为它背离了服务隔离的原则。 Michael Nygard 在他的微服务系列博客中提到了这一点。 Nygard是“ Re...
IDEA 整合 SSM 框架学习 认识 Spring 框架 更多详情请点击这里: 这里 Spring 框架是 Java 应用最广的框架,它的 成功来源于理念,而不是技术本身 ,它的理念包括 IoC (Inversion of Control,控制反转) 和 AOP(Aspect Oriented Progra...
Spring clean your dev machine Development machines can build up such a lot of cruft. Old versions, oudated programs and unused caches litter the hard drive. It’s good to take ti...
【威胁通告】Spring Web Flow 远程代码执行漏洞(CVE-2017-4971)... 阅读: 74 近日, Spring Web Flow发布了更新补丁修复了一个Spring Web Flow 在数据绑定上存在的一个漏洞(CVE-2017-4971, CNNVD-201706-147)。该漏洞源于在Model的数据绑定上没有指定相关model的具体属性,从而导...
码云推荐 | 轻量快速的对象池 Lite-pool 内容索引(Table of Contents) 1. Lite-pool 1.1. 简介 Lite-pool : 轻量快速的对象池 1.2. 安装前置条件 jdk 1.8+ maven-3.2.3+ 1.3. Maven依赖 ...