没有ID或名称的Spring Bean [英] Spring bean with no id or name

查看:227
本文介绍了没有ID或名称的Spring Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些Spring代码,并且看到一些没有ID或名称的bean def. 做这件事的人不在附近问. 该应用程序运行正常. 我不知道这必然意味着什么. 有人知道这是否意味着什么吗?

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 not familiar what this necessarily means. Anybody know if this means anything in particular?

推荐答案

某些bean不需要由上下文文件中的其他bean或以编程方式进行访问.因此,正如JacobM提到的那样,由于不需要引用,因此不需要ID或名称.

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.

例如 PropertyPlaceholderConfigurer ,它读取属性文件,然后允许在上下文定义中替换运行时属性.

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

示例定义为

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="myapp.properties" />
</bean>

JavaDoc提供了有关该对象的更多文档,但是在文件中,您可以仅通过使用标准模板替换占位符$ {...}来引用文件中的属性.

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 ${...}.

这篇关于没有ID或名称的Spring Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆