Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I update existing autowired properties when inserting a new bean?
    primarykey
    data
    text
    <p>We have component classes that autowire beans of a certain type:</p> <pre><code>@Component public class MyComponent { @Autowire public IValidators[] validators; } </code></pre> <p>Our application allows the creation of Groovy classes that get compiled at runtime and are registered with Spring using ScriptFactoryPostProcessor:</p> <pre><code>ConstructorArgumentValues args = new ConstructorArgumentValues(); args.addGenericArgumentValue(groovySourceLocation); //location is on the file system RootBeanDefinition def = new RootBeanDefinition(GroovyScriptFactory.class, args, null); BeanDefinitionRegistry r = (BeanDefinitionRegistry) this.applicationContext.getBeanFactory(); r.registerBeanDefinition(beanName, def); //beanName is the same as the class name //scriptFactoryPostProcessor is autowired into class from applicationConfig scriptFactoryPostProcessor.postProcessBeforeInstantiation(GroovyScriptFactory.class, beanName); </code></pre> <p>The groovy bean is created correctly as I can retrieve it from the applicationContext by the bean name or by the type. But the already autowired properties of components do not have the added bean. When the groovy class implements IValidator, I'd like any component classes that autowire IValidator types to be updated with new groovy bean added to the collection. How do I do this?</p> <p><strong>UPDATE</strong></p> <p>After looking through the source, I don't see anyway that Spring supports my expectation. My last hope was that I could ask for dependent beans of a type (similar to <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/beans/factory/config/ConfigurableBeanFactory.html#getDependentBeans%28java.lang.String%29" rel="nofollow">getDependentBeans(String beanName)</a>) but it does not exist and from the looks of things, Spring does not track dependencies based on type.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload