【发布时间】:2010-01-14 07:42:48
【问题描述】:
我在这里遇到的基本问题是我有一个 xml 文件被用作实用程序文件并导入到其他 xml 文件中。它定义了一系列用于连接到平台并为其提供接口的对象。此文件中的 bean 被定义为延迟初始化,因此如果您不想连接到平台,则不会,但如果您开始引用适当的 bean,那么一切都应该启动并运行。
我遇到的基本问题是,这个集合中的一个 bean 没有被其他任何一个明确引用,但它需要被构造,因为它将调用其他 bean 之一的方法以“激活” “ 它。 (它通过根据检测到的平台状态打开/关闭连接来充当看门人。
这是我拥有的那种 XML 设置的虚拟模型:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"
default-lazy-init="true">
<!-- Provides the connection to the platform -->
<bean id="PlatformConnection">
<constructor-arg ref="PlatformConnectionProperties" />
</bean>
<!-- This bean would be overriden in file importing this XML -->
<bean id="PlatformConnectionProperties"/>
<!-- Controls the databus to be on/off by listening to status on the Platform
(disconnections/reconnections etc...) -->
<bean lazy-init="false" class="PlatformStatusNotifier">
<constructor-arg ref="PlatformConnection" />
<constructor-arg ref="PlatformConnectionDataBus" />
</bean>
<!-- A non platform specific databus for client code to drop objects into -
this is the thing that client XML would reference in order to send objects out -->
<bean id="PlatformConnectionDataBus" class="DataBus"/>
<!-- Connects the DataBus to the Platform using the specific adaptor to manage the java object conversion -->
<bean lazy-init="false" class="DataBusConnector">
<constructor-arg>
<bean class="PlatformSpecificDataBusObjectSender">
<constructor-arg ref="PlatformConnection" />
</bean>
</constructor-arg>
<constructor-arg ref="PlatformConnectionDataBus" />
</bean>
</beans>
现在基本上我想在这里删除让这个东西正常工作所需的惰性初始化。客户端 XML 引用的对象是 PlatformConnection 和 PlatformConnectionDataBus。如果引用了其他 bean,我如何明确声明我希望构建它们?
【问题讨论】: