gpt4 book ai didi

spring - 在 Spring 中何时使用 以及何时使用

转载 作者:IT老高 更新时间:2023-10-28 13:45:30 24 4
gpt4 key购买 nike

何时使用 <ref bean="service" />以及何时使用 <ref local="service" /> Spring ?

最佳答案

Specifying the target bean by using the bean attribute of the ref tag is the most general form, and will allow creating a reference to any bean in the same BeanFactory/ApplicationContext (whether or not in the same XML file), or parent BeanFactory/ApplicationContext. The value of the bean attribute may be the same as either the id attribute of the target bean, or one of the values in the name attribute of the target bean.

<ref bean="someBean"/>

Specifying the target bean by using the local attribute leverages the ability of the XML parser to validate XML id references within the same file. The value of the local attribute must be the same as the id attribute of the target bean. The XML parser will issue an error if no matching element is found in the same file. As such, using the local variant is the best choice (in order to know about errors are early as possible) if the target bean is in the same XML file.

<ref local="someBean"/>

这是来自 Spring 源引用 here

关于spring - 在 Spring 中何时使用 <ref bean> 以及何时使用 <ref local>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8740322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com