Spring bean with no id or name

前端 未结 1 1354
时光取名叫无心
时光取名叫无心 2021-02-11 21:52

I\'m reviewing some Spring code, and I see a few bean defs that do not have an id or a name. The person who did it is not around to ask. The application is working fine. I am no

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-11 22:01

    Some beans are not required to be accessed by other beans in the context file or programmatically. So as mentioned by JacobM, they don't require an id or name as they're not referenced.

    Such an example would be a PropertyPlaceholderConfigurer, which reads a property file, then allows for runtime property replacement in the context definition.

    The example definition would be

    
      
    
    

    The JavaDoc provides further documentation on this object, but further on in the file you can reference properties from your file by just using the standard template replace placeholder ${...}.

    0 讨论(0)
提交回复
热议问题