Autowiring Unmanaged Beans Annotated With @Component

后端 未结 3 520
闹比i
闹比i 2020-12-28 12:11

I want to use @AutoWired to inject a non-managed bean configured with @Component into a managed bean. I\'m pretty sure I have the configuration right, but for some reason I

3条回答
  •  时光取名叫无心
    2020-12-28 12:15

    The previous response is not correct, in one aspect. You can autowire beans that are otherwise configured with xml.

    From section 3.4.5 in http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html:

    When using XML-based configuration metadata[2], you specify autowire mode for a bean definition with the autowire attribute of the element. The autowiring functionality has five modes. You specify autowiring per bean and thus can choose which ones to autowire.

    You can autowire by name, type and constructor. There is a crude example of this here: http://www.java2s.com/Code/Java/Spring/AutoWiring.htm

提交回复
热议问题