Spring中JavaConfig优于XML配置的好处? [英] Benefits of JavaConfig over XML configurations in Spring?

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

问题描述

以前,配置曾经在代码中进行过硬编码,后来又被外部化到.property文件中(为了避免使用硬编码值,避免为了更改配置而避免更改代码..etc),然后将其移至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. 搜索要简单得多,重构将是一件乐事.找一个豆子 定义会容易得多.
  1. Java is type safe. Compiler will report issues if you are configuring right bean class qualifiers.
  2. XML based on configuration can quickly grow big. [Yes we can split and import but still]
  3. Search is much simpler, refactoring will be bliss. Finding a bean definition will be far easier.

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

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

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

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

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