Как заполнить конструктор varargs, не используя applicationContext bean? - PullRequest
0 голосов
/ 18 марта 2020

У меня есть класс с конструктором varagrgs

public class ScpDataProvider {
------------
    public ScpDataProvider(DataStore... datastores) {
        for(DataStore d : datastores) {
            if(d.type.equals("SQL"))
                initSqlConnection(d);
            dataStores.AddDataStore(d);
        }
    }
------------
}

Как заполнить конструктор бобами хранилищ данных? Это приводит к 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>

1 Ответ

1 голос
/ 18 марта 2020

Вы можете использовать список ссылок:

<bean id="dataService" class="com.fressnapf.sdk.dataaccess.services.impl.ScpDataProvider">
<constructor-arg>
    <list>
         <ref bean="dataStore" />
         <ref bean="dataStore2" />
    </list>
</constructor-arg>

...