When to use and when to use in Spring?

前端 未结 5 1499
轻奢々
轻奢々 2020-12-14 06:51

When to use and when to use in Spring?

5条回答
  •  北海茫月
    2020-12-14 07:11

    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.

    
    

    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.

    
    

    This is from the Spring source reference here

提交回复
热议问题