我有以下bean配置:
<bean class="com.MyFactoryBean" depends-on="otherBean" scope="prototype">
<property name="dataSource" ref="defaultDataSource"/>
<property name="myCustomProperties">
<props>
<prop key="test">HELLO</prop>
</props>
</property>
</bean>
然后我的班级
public class MyFactoryBean {
public MyFactoryBean(final DataSource dataSource) {
// myConstructor
}
public void setMyCustomProperties(final Properties myCustomProperties) {
System.out.println("Hi");
}
}
当dataSource传递给构造函数时,customProperties不是。
答案 0 :(得分:4)
<强>类强>
public class MyFactoryBean {
private DataSource dataSource;
private Properties myCustomProperties;
public void setDataSource(final DataSource dataSource) {
this.dataSource = dataSource;
}
public void setMyCustomProperties(final Properties myCustomProperties) {
this.myCustomProperties = myCustomProperties;
}
}
XML配置
<bean class="com.MyFactoryBean" depends-on="otherBean">
<property name="dataSource" ref="defaultDataSource"/>
<property name="myCustomProperties">
<props>
<prop key="test">HELLO</prop>
</props>
</property>
</bean>
此外,如果您想使用混合解决方案,您可以使用Class及以下配置。
<bean class="com.MyFactoryBean" depends-on="otherBean">
<constructor-arg ref="defaultDataSource" />
<property name="myCustomProperties">
<props>
<prop key="test">HELLO</prop>
</props>
</property>
</bean>
答案 1 :(得分:0)
问题是这个bean实际上并没有被加载,但它是从另一个位置手动构建的