Вопрос

I was wondering what is difference between those two? RuntimeBeanReference worked for me rather RuntimeBeanNameReference for the following scenario:

    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClassName(beanClassName);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("dataSource", new RuntimeBeanReference(dataSourceBeanName));
    bd.setPropertyValues(pvs);
Это было полезно?

Решение

You are using RuntimeBeanReference correctly. The code you posted is basically what Spring generates when you have

<bean class="beanClassName">
    <property name="dataSource" ref="dataSourceBeanName" />
</bean>

At run time, Spring will find the bean referenced by dataSourceBeanName and inject it.

RuntimeBeanNameReference, as far as I can tell (there are very few uses of it), is basically used to inject the bean name while validating that a bean with that name exists in the context.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top