Difference between using bean id and name in Spring configuration file

后端 未结 6 1126
忘了有多久
忘了有多久 2020-12-04 05:24

Is there any difference between using an id attribute and name attribute on a element in a Spring configuration file?

6条回答
  •  一整个雨季
    2020-12-04 06:24

    Either one would work. It depends on your needs:
    If your bean identifier contains special character(s) for example (/viewSummary.html), it wont be allowed as the bean id, because it's not a valid XML ID. In such cases you could skip defining the bean id and supply the bean name instead.
    The name attribute also helps in defining aliases for your bean, since it allows specifying multiple identifiers for a given bean.

提交回复
热议问题