cemb
cemb

Reputation: 19

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

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>

Upvotes: 2

Views: 2967

Answers (2)

Cristian Botiza
Cristian Botiza

Reputation: 439

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.

Upvotes: 0

Michael
Michael

Reputation: 3326

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

Upvotes: 1

Related Questions