Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 spring 配置中,使用 name 和 id 有什么区别?我知道 XML 将“id”属性限制为在文档中是唯一的,并限制在 id 中使用的字符。但是否则在声明 bean 时,使用“name”属性与“id”属性有什么区别?
本质上,这实际上只是一个 XML 问题。但是你也可以使用 name 属性来为 bean 指定别名,使用在 id 中非法的字符,我认为。
通常,您应该尽可能尝试使用 id 而不是 name。这样,解析器可以为您捕获重复项。