What is the meaning and what it does autowire=“default” in spring in applicationcontext.xml file

筅森魡賤 提交于 2020-01-04 14:07:13

问题


What is the meaning of autowire="default" and what it does if autowire="default" in applicationcontext.xml file

Example code Snippet -

<beans>
  <bean name="aa" class="Address">
  </bean>   
  <bean id="person" class="Person" autowire="default">
  </bean>
</beans>

回答1:


That the autowiring is not performed. autowire="default" is the same as putting autowire="no", which is:

no – Default, no auto wiring, set it manually via “ref” attribute

source: http://www.mkyong.com/spring/spring-auto-wiring-beans-in-xml/

EDIT: if you declare a bean with autowire="default" is the same as declaring it with autowire="no":

By default spring bean autowiring is turned off. Spring bean autowire default value is “default” that means no autowiring is to be performed. autowire value “no” also have the same behavior.

source: http://www.journaldev.com/2623/spring-bean-autowire-by-name-type-constructor-autowired-and-qualifier-annotations-example




回答2:


The documentation is indeed confusing. The 'default' value is not even documented in the beans xsd http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

If you resort to annotation driven auto-wiring, 'default' is by type. Your best bet is to play with the options and enable Spring's DEBUG logging. I wouldn't use the default attribute value - better be explicit if you do have to use it.



来源:https://stackoverflow.com/questions/29164330/what-is-the-meaning-and-what-it-does-autowire-default-in-spring-in-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!