<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="ink2" class="hr.BlackInk"></bean>
<bean id="ink" class="hr.ColorInk"> </bean>
<bean id="page" class="hr.B5Page"></bean>
<!-- autowire="byName" 根据名称自动 注入 -->
<!--autowire="byType" 根据属性的类型自动找到相应的类 注入 -->
<bean id="printer" class="hr.Printer" autowire="byType">
<!--
<property name="ink" ref="ink2"></property>
<property name="page" ref="page"></property>
-->
</bean>
</beans>
Spring的自动注入
最新推荐文章于 2024-09-13 22:48:29 发布