在我的spring application-config.xml中我有
<bean id=“shapeFactory" class="com.shapes.ShapeFactory" />
<bean id=“shapeHelper" class="com.shape.ShapeHelper">
<constructor-arg value=“#{shapeFactory.createDefaultShape()}” />
</bean>
但是在我的shapeFactory类中,我还有一个方法,其签名类似于
public Shape createShape(final Collection<Class<? extends Throwable>>,
final Collection<Class<? extends Throwable>> ,
final double ,
final double ,
final int , final double)
如何通过调用createShape来实例化shapeHelper对象,该方法将不同的参数作为参数。
编辑:为了使示例简单,如果说我有
public Shape createShape(final double ,
final double ,
final int , final double)
我怎么能调用上面的任何方法并使返回Shape成为shapeHelper构造函数的参数?
答案 0 :(得分:1)
一种方法是使用工厂主体
创建一个名为shape的bean <bean id="shape " class="..Shape" factory-bean="shapeFactory" factory-method="createDefaultShape">
<constructor-arg name="argNAme" type="java.lang.Long" value="1">
<!--all args go here ? THEY WILL passed as parameters to the method createDefaultShape -->
</constructor-arg>
然后在你的shapeHelper中你可以简单地引用那个bean
<bean id=“shapeHelper" class="com.shape.ShapeHelper">
<constructor-arg ref="shape" />
</bean>