在 Spring 框架中使用抽象工厂

编程入门 行业动态 更新时间:2024-10-28 20:22:43
本文介绍了在 Spring 框架中使用抽象工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些抽象工厂

public interface AbstractViewersFactory {
    IAbstractShapeViewer createRectangle(BaseOperationsListener<RectangleDTO> p);
    IAbstractShapeViewer createOval(BaseOperationsListener<OvalDTO> p);
    IAbstractShapeViewer createTriangle(BaseOperationsListener<TriangleDTO> p);
}

及其实现Draw2DViewersFactory.现在,我想创建一些类来负责按模型创建演示者/查看者并由 Spring 对其进行配置.所以,我需要在 .xml 配置中描述它应该调用什么方法.它可以是这样的(伪配置)

And Its implementation Draw2DViewersFactory. Now, I want create some class that will take responsibility for creating presenters/viewers by model and configurate it by Spring. So, I need describe in .xml configuration what method it should call. It can be something like this (pseudo config)

<bean creator>
<constructor-args>
<list>
    <bean describe-item> <constructor-args>model=Rectangle.class, method-for-viewer-create="createRectangle"</args>
    <bean describe-item> <constructor-args>model=Oval.class, method-for-viewer-create="createOval"</args>
<list>
</constructor-args>
</bean>

我该怎么做?

谢谢.

推荐答案

尽管您的问题很不清楚,但我想我已经了解了您想知道的内容.你可以定义一个spring bean作为工厂实例,然后像这样设置这个bean的工厂方法:

Even though your question is very unclear, I think I got what you wanted to know. You can define a spring bean as a factory instance and then set the factory method of this bean like this:

<bean id="myFactoryBean"
  class="AbstractViewersFactory">

  <bean id="exampleBean"
  factory-bean="myFactoryBean"
  factory-method="createRectangle"/>

希望这会有所帮助.谷歌这个以获取更多信息:p

Hope this helps. Google this for further information :p

问候

这篇关于在 Spring 框架中使用抽象工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 16:03:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/808731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抽象   框架   工厂   Spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!