在列表中传递多个实现
我是 Spring 新手。我有这个问题困扰我一段时间了。任何帮助将不胜感激。
有一个调用 getter 方法的接口。
interface MessageHandler{
public List GetMessageCheckerList();
}
还有另一个名为 MessageChecker 的接口,它有多个实现。 例如 MessageChecker1、TestChecker 等(现在假设为 2)
现在我如何在配置 xml 文件中定义它。
我实际上已经创建了 bean,
这是其余的代码
<bean id="checkerList" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="HL7Checker"/>
</list>
</constructor-arg>
</bean>
<bean id="HL7Checker" class="com.kahootz.messagereceiver.HL7CheckerImpl">
<property name="messageExecutor" ref="Executor"/>
</bean>
请建议
当我实际使用 main 方法运行程序时,我得到了其中一个 bean 的句柄,HL7Checker 应该以列表形式传递给 ID=messageHandler 的 Bean。但当我打印出清单时。它是空的。
在不使用 spring 且仅使用 getter 和 setter 方法的情况下,我可以“设置”列表并使用 Get 检索它。
I am New to Spring.I have this question which has been bothering me for a while now. Any help would be appreciated.
There is an Interface which calls a getter method.
interface MessageHandler{
public List GetMessageCheckerList();
}
There is another Interface called MessageChecker which has multiple Implementations.
Say MessageChecker1, TestChecker, etc. (lets assume 2 for now )
Now how do i define this in the configuration xml file.
I actually have the bean created ,
here is the rest of the code
<bean id="checkerList" class="java.util.ArrayList">
<constructor-arg>
<list>
<ref bean="HL7Checker"/>
</list>
</constructor-arg>
</bean>
<bean id="HL7Checker" class="com.kahootz.messagereceiver.HL7CheckerImpl">
<property name="messageExecutor" ref="Executor"/>
</bean>
Please Advice
When I actually run the program using a main method, I get the handle of one of the beans, The HL7Checker should be passed in a list to the Bean with ID=messageHandler. But when i print out the list. It is empty.
Without using spring and only using getter and setter methods , i am able "set" a list and retrieve it using Get.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
标记需要对象的名称,而不是类的名称。因此,您需要先定义一个
才能引用它。com.Test
。首先,它应该只包含小写字母。其次,您应该是该名称的所有者。<ref>
tag expects the name of an object, not the name of a class. So you need to define a<bean id="testChecker" class="com.test.TestChecker" />
before you can reference it.com.Test
. First, it should contain only lowercase letters. Second, you should be the owner of that name.