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阅读原文】。感谢您的支持!

您可能感兴趣的

一线互联网公司Java高级面试题总结 Java重点知识 多线程(线程状态、线程并发,Synchronized与Lock的区别和底层原理,常用的锁及其使用场景和原理, volatile和ThreadLocal解决了什么问题,CAS在Java中的实现 ...
Reproducible Research: Write your Clinical Chemist... (This article was first published on The Lab-R-torian , and kindly contributed toR-bloggers) Abstract Backgroun...
Spring Batch Tutorial: Batch Processing Made Easy ... Batch processing—typified by bulk-oriented, non-interactive, and frequently long running, background execution—is wid...
MyBatis+Spring MVC开发指南(二) 前言 接 《MyBatis+Spring MVC开发指南(一)》 ,本篇博客将涵盖MyBatis高级映射(一对一,一对多、多对多)、延迟加载、缓存原理分析(一级缓存、二级缓存)、MyBatis和Spring的整合、逆向工程等主题...
DockOne分享:乐高式微服务化改造 1 微服务总览 大家好,我是沈斌,英文名Emac,来自 杏仁医生 ,负责平台架构组。今天我分享的主题是微服务化改造。在正式开始之前,我想先跟大家简单聊一下我对Martin Fowler的 微服务定义 中三个关键词(small,inde...