Spring - 所有豆子都经过加工吗?
我有一个正在编写的 LDAP 应用程序的 beans.xml 文件。我允许用户选择多个 LdapContextSource。对于每个 bean,我都有一个不同的 bean,例如,
<bean id="ldapTemplate" class="yyy.LdapTemplate">
<constructor-arg ref="contextSource1" />
</bean>
<bean id="contextSource1" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource2" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource3" class="xxx.LdapContextSource">
...
</bean>
您可以看到这些上下文源 bean 中只有一个被实例化,因为 ldapTemplate bean 只引用了一个。然而,当我运行我的应用程序时,stdout 中的 Spring 日志消息提供有关每个上下文源的信息,即使只依赖一个上下文源。
2011 年 1 月 25 日上午 11:56:36 org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet 信息:未设置属性“userDn” - 匿名上下文将用于读写操作 一月 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet 信息:未设置属性“userDn” - 匿名上下文将用于读写操作 一月 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet 信息:未设置属性“userDn” - 匿名上下文将用于读写操作
我的问题是:
(1)Spring 对未引用/依赖的上下文源做什么?它们永远不应该在我的应用程序中实例化,而且令我担心的是 Spring 为每个 bean 提供日志信息。
(2) 我是否应该注释掉应用程序中未使用的上下文源bean?如果不注释它们会产生什么后果?标准做法是什么?
谢谢,
克特姆
I have a beans.xml file for an LDAP application that I am writing. I am allowing the user the choice of several LdapContextSource(s). For each one I have a different bean, e.g.
<bean id="ldapTemplate" class="yyy.LdapTemplate">
<constructor-arg ref="contextSource1" />
</bean>
<bean id="contextSource1" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource2" class="xxx.LdapContextSource">
...
</bean>
<bean id="contextSource3" class="xxx.LdapContextSource">
...
</bean>
You can see that only one of these context source beans gets instantiated, because only one is referred to by the ldapTemplate bean. However, when I run my application, my Spring log messages in stdout provide information about each context source, even though only one is depended on.
Jan 25, 2011 11:56:36 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property 'userDn' not set - anonymous context will be used for read-write operations
Jan 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property 'userDn' not set - anonymous context will be used for read-write operations
Jan 25, 2011 11:56:37 AM org.springframework.ldap.core.support.AbstractContextSource afterPropertiesSet
INFO: Property 'userDn' not set - anonymous context will be used for read-write operations
My questions are:
(1) What is Spring doing with the context sources that are not referred to / depended on? They should never be instantiated in my application, and it worries me that Spring is providing log information for each of these beans.
(2) Should I comment out the context source beans that are not used in the application? What are the consequences of leaving them uncommented? What is the standard practice?
Thanks,
ktm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以看看 延迟加载豆子。这是 Spring 2.5.x 文档的相关解释...
为了完整起见,这里有一个例子......
Maybe you could check out Lazy Loading of Beans. Here is the relevant explanation from the Spring 2.5.x docs...
For the sake of completness here is an example...