spring.codeconfig vs xml configuration

后端 未结 2 1244
梦谈多话
梦谈多话 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:19

    Just to highlight one thing, you can mix and match configuration styles. From within a CodeConfig class you can refere to XML config files using the [ImportResource] attribute (see here), and in the XML you can use the namespace (see here).

    Cheers, Mark

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题