Spring 中 JavaConfig 相对于 XML 配置的优势? [英] Benefits of JavaConfig over XML configurations in Spring?

查看:22
本文介绍了Spring 中 JavaConfig 相对于 XML 配置的优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早期的配置用于在代码中进行硬编码,后来它被外部化为 .property 文件(为了避免硬编码值,避免为了更改配置而更改代码......等等)然后它转移到XML(为了更加标准化,无错误..等)

Earlier the configurations used to be in hard coded in the code, later it was externalized to .property files (for sake of avoiding hard coded values, avoiding changing code for the sake of changing configurations..etc) then it moved to XML (for sake of being more standardized, error free..etc)

现在,在阅读 Spring 3 中的 @Configuration 时,看起来我们又回到了最初的方法.

Now, while reading about @Configuration in Spring 3 , looks like we are again moving back to the initial approach.

为什么我们要在代码中硬编码配置而不是外化了吗?

Why would we want to hard-code configurations in the code rather than having it externalized ?

推荐答案

有一些优点

  1. Java 是类型安全的.如果您是,编译器将报告问题配置正确的 bean 类限定符.
  2. 基于配置的 XML 可以迅速变大.[是的,我们可以分开并导入但仍然]
  3. 搜索更简单,重构会很幸福.寻找一颗豆子定义会容易得多.

仍然有人喜欢 XML 配置并继续这样做.

There are still people who like XML configuration and continue to do it.

参考资料:Java 配置优势更多原因

这篇关于Spring 中 JavaConfig 相对于 XML 配置的优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆