Announcement Announcement Module
No announcement yet.
@Autowire by name? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Autowire by name?

    I was wondering if someone here would be kind enough to clear up my confusion about auto wiring.

    What I'd like to do is specify the fields I want to auto wire with @Autowired, but have them wired by name, rather than type, or @Qualifier("bla").

    Looking at the Spring code, it seems that something like this is possible:
    public class MyClass() { ... }
    but I don't understand how to invoke the processing of @Configurable annotations. It seems that I somehow need to utilize the BeanConfigurerSupport class, but it's not obvious to me how to do that. The comments say something about AspectJ integration?

    I tried setting the AUTOWIRE_BY_NAME mode on the BeanDefinition directly with a MergedBeanDefinitionPostProcessor, but this mechanism seems to not actually look at the @Autowired annotations, but rather just goes after all PropertyDescriptors on the bean.

    So, is it possible to do what I'm trying to do?
    Last edited by vace117; Oct 26th, 2011, 08:15 PM.

  • #2
    That auto wire has nothing to do with @Autowired (confusing I know) it is the replacement for the auto wire xml attribute which basically scans getters/setters to do auto wiring.

    So in short what you are trying to do isn't possible out-of-the-box. If you would want that you would need to reimplement/override the functionality of the AutowireAnnotationBeanFactoryPostProcessor next to not using context:annotation-driven or component-scan elements anymore (you would need to register all Bean(Factory)PostProcessors by hand instead of relying on the defaults).