spring IOC bean间关系
1.0 继承关系
实体
package com.java.test5; import java.util.*; /** * @author nidegui * @create 2019-06-22 14:45 */ public class People { private Integer id; private String name; private String age; private String className; public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } @Override public String toString() { return "People{" + "id=" + id + ", name='" + name + '\'' + ", age='" + age + '\'' + ", className='" + className + '\'' + '}'; } }
beans.xml
<?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="abstractPeople" class="com.java.test5.People" abstract="true"> <property name="className" value="5班"></property> <property name="age" value="15"></property> </bean> <!--张三李四继承people--> <bean id="zhangsan" parent="abstractPeople"> <property name="id" value="1"></property> <property name="name" value="zhangsan"></property> </bean> <bean id="lisi" parent="abstractPeople"> <property name="id" value="2"></property> <property name="name" value="lisi"></property> <property name="age" value="20"></property> </bean> </beans>
2.0 依赖关系
<!--depends-on="",依赖关系--> <bean id="zhangsan" parent="abstractPeople" depends-on=""> <property name="id" value="1"></property> <property name="name" value="zhangsan"></property> </bean>
3.0引用关系
加入另一个bean,引用。如前面讲到的dog类