防水自己如何建设网站,长沙推广网站,怎么仿网站链接,Wordpress query 参数一、概述 自动装配是根据指定规则#xff08;属性名称或者属性类型#xff09;#xff0c;Spring自动将匹配的属性值进行注入。
二、分类 xml自动装配分为按照属性名称自动装配#xff08;byName#xff09;和按照属性类型自动装配#xff08;byType#xff09;。
2.1…一、概述 自动装配是根据指定规则属性名称或者属性类型Spring自动将匹配的属性值进行注入。
二、分类 xml自动装配分为按照属性名称自动装配byName和按照属性类型自动装配byType。
2.1、byName
AllArgsConstructor
NoArgsConstructor
Data
public class Department implements Serializable {/*** 部门名称*/private String name;}Data
AllArgsConstructor
NoArgsConstructor
public class Employee implements Serializable {/*** 员工名称*/private String name;/*** 性别*/private String gender;/*** 部门*/private Department department;
}?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean idemployee classorg.star.entity.Employee autowirebyNameproperty namename value李白/propertyproperty namegender value男/propertyproperty namedepartment refdepartment/property/beanbean iddepartment classorg.star.entity.Departmentproperty namename value研发部/property/bean/beans/*** IOC操作bean管理xml自动装配-byName*/
Test
public void beanManagementTest12() {ClassPathXmlApplicationContext context new ClassPathXmlApplicationContext(applicationContext12.xml);Employee employee context.getBean(employee, Employee.class);System.out.println(byName employee employee);
}
// 控制台打印结果
byName employee Employee(name李白, gender男, departmentDepartment(name研发部))
2.2、byType
AllArgsConstructor
NoArgsConstructor
Data
public class Department implements Serializable {/*** 部门名称*/private String name;}Data
AllArgsConstructor
NoArgsConstructor
public class Employee implements Serializable {/*** 员工名称*/private String name;/*** 性别*/private String gender;/*** 部门*/private Department department;
}?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean idemployee classorg.star.entity.Employee autowirebyTypeproperty namename value李白/propertyproperty namegender value男/propertyproperty namedepartment refdepartment/property/beanbean iddepartment classorg.star.entity.Departmentproperty namename value研发部/property/bean/beans/*** IOC操作bean管理xml自动装配-byType*/
Test
public void beanManagementTest13() {ClassPathXmlApplicationContext context new ClassPathXmlApplicationContext(applicationContext13.xml);Employee employee context.getBean(employee, Employee.class);System.out.println(byType employee employee);
}
// 控制台打印结果
byType employee Employee(name李白, gender男, departmentDepartment(name研发部))