当前位置: 首页 > 工具软件 > Wiring > 使用案例 >

Spring Auto-Wiring Beans

陶炫明
2023-12-01
In Spring framework, you can wire beans automatically with auto-wiring feature. To enable it, just define the “autowire” attribute in <bean>.

    <bean id="customer" class="com.mkyong.common.Customer" autowire="byName" />

In Spring, 5 Auto-wiring modes are supported.

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

    byName – Auto wiring by property name. If the name of a bean is same as the name of other bean property, auto wire it.

    byType – Auto wiring by property data type. If data type of a bean is compatible with the data type of other bean property, auto wire it.

    constructor – byType mode in constructor argument.

    autodetect – If a default constructor is found, use “autowired by constructor”; Otherwise, use “autowire by type”.

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

 类似资料:

相关阅读

相关文章

相关问答