spring.codeconfig vs xml configuration

后端 未结 2 1243
梦谈多话
梦谈多话 2021-01-24 04:08

I\'ve been using spring.net with xml configuration for some times, and I just saw that spring team released CodeConfig a month ago.

What I like about the xml config is t

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 04:39

    With code config, possible benefits you could get are:

    • Better refactoring support; e.g. renaming an injected property
    • More compact configuration, compared to xml
    • Developers can use code, in which they are often more at home than in xml

    Benefit of the last point is also that developers new to the framework will have a significantly less steep learning curve than with the xml config.

    From the docs:

    While there are several positive aspects to expressing configuration metadata in XML files, there are also many problems with this approach including the verbosity of XML and its heavy dependence on string-literals which are both prone to typing errors and unusually resistant to most modern refactoring tools in use today. The CodeConfig approach removes these problems by providing a type safe, code-based, approach to dependency injection. It keeps the configuration metadatda external to your class so your class can be a POCO, free of any DI related annotations.

提交回复
热议问题