# 2.4　通过 XML 装配 bean

到此为止，我们已经看到了如何让 Spring 自动发现和装配 bean，还看到了如何进行手动干预，即通过 JavaConfig 显式地装配 bean。但是，在装配 bean 的时候，还有一种可选方案，尽管这种方案可能不太合乎大家的心意，但是它在 Spring 中已经有很长的历史了。

在 Spring 刚刚出现的时候，XML 是描述配置的主要方式。在 Spring 的名义下，我们创建了无数行 XML 代码。在一定程度上，Spring 成为了 XML 配置的同义词。

尽管 Spring 长期以来确实与 XML 有着关联，但现在需要明确的是，XML 不再是配置 Spring 的唯一可选方案。Spring 现在有了强大的自动化配置和基于 Java 的配置，XML 不应该再是你的第一选择了。

不过，鉴于已经存在那么多基于 XML 的 Spring 配置，所以理解如何在 Spring 中使用 XML 还是很重要的。但是，我希望本节的内容只是用来帮助你维护已有的 XML 配置，在完成新的 Spring 工作时，希望你会使用自动化配置和 JavaConfig。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://potoyang.gitbook.io/spring-in-action-v4/di-2-zhang-zhuang-pei-bean/2.4-tong-guo-xml-zhuang-pei-bean.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
