读书人

3-22在同一个工场中注入Bean

发布时间: 2012-08-25 10:06:20 作者: rapoo

3-22在同一个工厂中注入Bean
使用ref指定要注入的值:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="                http://www.springframework.org/schema/beans                http://www.springframework.org/schema/beans/spring-beans.xsd">    <bean id="encyclopedia" ref="encyclopedia"/>    </bean></beans>

使用bean的别名进行注入(name="knowitall"):
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:util="http://www.springframework.org/schema/util"       xsi:schemaLocation="                http://www.springframework.org/schema/beans                http://www.springframework.org/schema/beans/spring-beans.xsd                http://www.springframework.org/schema/util                http://www.springframework.org/schema/util/spring-util.xsd">    <bean id="encyclopedia"          name="knowitall"          value="13700000000"/>                <entry key="ConstantOfLife" value="326190476"/>            </util:map>        </constructor-arg>    </bean>    <bean id="oracle" ref="knowitall"/>    </bean></beans>

读书人网 >软件架构设计

热点推荐