Spring依赖注入例子

来源:互联网 发布:淘宝csgo买哪个版本 编辑:程序博客网 时间:2024/06/05 22:44

从Spring手册中摘录的一段,有关依赖注入的例子

The following example uses XML-based configuration metadata for setter-based DI. A small part of a Spring XML configuration file specifies some bean definitions:

<bean id="exampleBean" class="examples.ExampleBean"><!-- setter injection using the nested <ref/> element --><property name="beanOne"><ref bean="anotherExampleBean"/></property><!-- setter injection using the neater 'ref' attribute --><property name="beanTwo" ref="yetAnotherBean"/><property name="integerProperty" value="1"/></bean><bean id="anotherExampleBean" class="examples.AnotherBean"/><bean id="yetAnotherBean" class="examples.YetAnotherBean"/>