0
private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) 
      definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
}

What is the difference between AutowireCapableBeanFactory.AUTOWIRE_NO and AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE?

soranico
  • 5
  • 4
  • I noticed that Spring created BeanDefinition using AUTOWIRE_NO, we can use @autowire annotation to complete attribute injection. But mybatis-spring creates BeanDefinition using AUTOWIRE_BY_TYPE and also provides a set method. What is the difference between the two? – soranico May 01 '20 at 04:47
  • The autowire mode and `@Autowired` are not related. The `AUTOWIRE_BY_TYPE` predates the annotation support and would try to autowire properties (ie. setters) on beans based on the type they expect. So a `setDataSource(DataSource ds)` would get automatically autowired with a datasource typed bean. Again this is **NOT** related to annotation based autowiring. – M. Deinum May 01 '20 at 06:43
  • @soranico, editing your comment into your question might be a good idea. – marko-36 May 01 '20 at 06:45
  • @M.Deinum That is to say Autowired annotation is just a technique to inject attributes? – soranico May 01 '20 at 21:36
  • It is explicitly telling to autowire that dependency. – M. Deinum May 03 '20 at 06:09

1 Answers1

0

AUTOWIRE_NO - no external autowiring at all.

AUTOWIRE_BY_TYPE - autowiring bean properties by type.

REF

There is another answer that explains this difference - Answer

Hemant
  • 1,403
  • 2
  • 11
  • 21