[英]How to fill a varargs contructor unsing applicationContext beans?
I have a class with a varagrgs contructor我有一个带有 varagrgs 构造函数的类
public class ScpDataProvider {
------------
public ScpDataProvider(DataStore... datastores) {
for(DataStore d : datastores) {
if(d.type.equals("SQL"))
initSqlConnection(d);
dataStores.AddDataStore(d);
}
}
------------
}
How to fill the contructor with beans of datastores?如何用数据存储的 bean 填充构造函数? This results in
Attribute "ref" is not allowed here
这导致
Attribute "ref" is not allowed here
<bean id="dataService"
class="com.fressnapf.sdk.dataaccess.services.impl.ScpDataProvider">
<constructor-arg>
<array>
<bean ref="dataStore" />
<bean ref="dataStore2" />
</array>
</constructor-arg>
</bean>
You can use list of refs:您可以使用参考列表:
<bean id="dataService" class="com.fressnapf.sdk.dataaccess.services.impl.ScpDataProvider">
<constructor-arg>
<list>
<ref bean="dataStore" />
<ref bean="dataStore2" />
</list>
</constructor-arg>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.