在列表中传递多个实现

发布于 2024-10-04 21:48:12 字数 935 浏览 0 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2024-10-11 21:48:12
  1. 几乎所有的名称都不符合 Java 命名约定。这使得其他人很难理解你的代码。
  2. 标记需要对象的名称,而不是的名称。因此,您需要先定义一个 才能引用它。
  3. 不要使用包名称 com.Test。首先,它应该只包含小写字母。其次,您应该是该名称的所有者。
  1. Almost all of your names do not conform to the Java Naming Conventions. That makes it hard for others to understand your code.
  2. The <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.
  3. Don't use the package name com.Test. First, it should contain only lowercase letters. Second, you should be the owner of that name.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文