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

查看:34
本文介绍了JavaConfig 相对于 Spring 中的 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 配置优势更多原因

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

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