说我有以下课程
public class AbcFactory{
@Autowired
private Builder1 builder1;
@Autowired
private Builder2 builder2;
public Builder<Employee > getBuilder(Employee employee) {
if (employee.isMale(employee)) {
return builder1;
} else {
return builder2;
}
}
如何从abcFactory.getBuilder()获取returnType作为另一个bean id的属性。
我试过的东西看起来像这样
<property name="builder">
?????
</property>
答案 0 :(得分:1)
试,
<bean id="emp" class="com.pack.Employee"/>
<bean id="factory" class="com.pack.AbcFactory">
</bean>
<bean id="result" class="com.pack.Builder"
factory-bean="factory" factory-method="getBuilder">
<constructor-arg ref="emp"/>
</bean>
答案 1 :(得分:0)
Aren您将静态配置(启动时间)与动态行为(运行时)混合在一起。 Spring无法根据尚未发生的调用进行设置。 或许&#34;员工&#34;是一个豆本身?在这种情况下请参阅JavaConfig。