问题
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