spring--Autowired setter 方法
package Autowired; /**
* Created by luozhitao on 2017/8/9.
*/
public class person1 {
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getAdress() {
return adress;
} public void setAdress(String adress) {
this.adress = adress;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} private String name;
private String adress;
private int age; }
package Autowired; import org.springframework.beans.factory.annotation.Autowired; /**
* Created by luozhitao on 2017/8/9.
*/
public class Customer1 { public int getType() {
return type;
} public void setType(int type) {
this.type = type;
} public String getAction() {
return action;
} public void setAction(String action) {
this.action = action;
} public person1 getPerson() {
return person;
} @Autowired
public void setPerson(person1 person) {
this.person = person;
} private int type;
private String action;
private person1 person; }
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config /> <bean id="person" class="Autowired.person1">
<property name="name" value="猫儿"/>
<property name="adress" value="beijing"/>
<property name="age" value="1"/>
</bean> <bean id="customer" class="Autowired.Customer1">
<property name="type" value="2"/>
<property name="action" value="buy"/>
</bean>
</beans>
通过构造方法注入:
package Autowired; import org.springframework.beans.factory.annotation.Autowired; /**
* Created by luozhitao on 2017/8/9.
*/
public class Customer2 {
public int getType() {
return type;
} public void setType(int type) {
this.type = type;
} public String getAction() {
return action;
} public void setAction(String action) {
this.action = action;
} public person1 getPerson() {
return person;
} public void setPerson(person1 person) {
this.person = person;
} private int type;
private String action;
private person1 person; @Autowired
public Customer2(person1 person){ this.person=person;
} }
通过字段进行注入:
package Autowired; import org.springframework.beans.factory.annotation.Autowired; /**
* Created by luozhitao on 2017/8/9.
*/
public class Customer3 { public int getType() {
return type;
} public void setType(int type) {
this.type = type;
} public String getAction() {
return action;
} public void setAction(String action) {
this.action = action;
} public person1 getPerson() {
return person;
} private int type;
private String action;
@Autowired
private person1 person; }
spring--Autowired setter 方法的更多相关文章
- SpringBoot 构造器注入、Setter方法注入和Field注入对比
0. 引入 今天在看项目代码的时候发现在依赖注入的时候使用了构造器注入,之前使用过 Field 注入和 Setter 方法注入,对构造器注入不是很了解.经过查阅资料看到,Spring 推荐使用构造器注 ...
- spring构造函数注入、setter方法注入和接口注入
Spring开发指南中所说的三种注入方式: Type1 接口注入 我们常常借助接口来将调用者与实现者分离.如: public class ClassA { private InterfaceB clz ...
- Spring第六弹—-依赖注入之使用构造器注入与使用属性setter方法注入
所谓依赖注入就是指:在运行期,由外部容器动态地将依赖对象注入到组件中. 使用构造器注入 1 2 3 4 <constructor-arg index=“0” type=“java.lang. ...
- spring 构造方法注入和setter方法注入的XML表达
1.构造方法注入 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC ...
- spring setter方法注入
<bean id="dao" class="Dao"></bean> <bean id="service" c ...
- Spring中使用事务搭建转账环境方法二 相对简便的注解方法 ——配置文件注入对象属性需要setter方法 注解方法,不需要生成setter方法
XML配置文件代码如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...
- Spring@Autowired注解与自动装配
1 配置文件的方法 我们编写spring 框架的代码时候.一直遵循是这样一个规则:所有在spring中注入的bean 都建议定义成私有的域变量.并且要配套写上 get 和 set方法. Boss ...
- 【转】Spring@Autowired注解与自动装配
1 配置文件的方法 我们编写spring 框架的代码时候.一直遵循是这样一个规则:所有在spring中注入的bean 都建议定义成私有的域变量.并且要配套写上 get 和 set方法. Boss ...
- spring @Autowired或@Resource 的区别
1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认按类型装配(这个注解是属于spring的),默认情况下必 ...
- spring @Autowired与@Resource的区别
1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认按类型装配(这个注解是属业spring的),默认情况下必 ...
随机推荐
- spark数据监控实战
版权申明:转载请注明出处.文章来源:http://bigdataer.net/?p=248 排版乱?请移步原文获得更好的阅读体验 1.概述 数据准确性,稳定性,时效性是数据开发中需要重点关注的,一 ...
- tyvj 1062 合并傻子 区间dp,典型模型石子归并
P1062 合并傻子 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 从前有一堆傻子,钟某人要合并他们~但是,合并傻子是要掉RP的...... 描述 在一个园 ...
- Python 有点意思
基本语法 >>> width = 20 >>> height = 2 * 3 >>> width * height 120 >>> ...
- 十二道MR习题 – 1 – 排序
题目: 一个文件,大小约为100G.文件的每一行都是一个数字,要求对文件中的所有数字进行排序. 对于这个题目,了解过Hadoop的同学可以笑而不语了.即使用spark实现也是非常简单的事情. 先说下如 ...
- c# 使用事务
EcAttendanceMatterBLL.OpenTransaction(); DbTransaction Tran = EcAttendanceMatterBLL.Transaction; _wf ...
- numpy 矩阵归一化
new_value = (value - min)/(max-min) def normalization(datingDatamat): max_arr = datingDatamat.max(ax ...
- Pycharm for mac 快捷键
cmd b 跳转到声明处(cmd加鼠标) opt + 空格 显示符号代码 (esc退出窗口 回车进入代码) cmd []光标之前/后的位置 opt + F7 find usage cmd backsp ...
- Python StringIO实现内存缓冲区中读写数据
StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以像操作磁盘文件那样来操作StringIO.这篇文章主要介绍了Python StringIO模块,此模块 ...
- 【译】:python中的colorlog库
本文翻译自colorlog官方文档 一. 描述 colorlog.ColoredFormatter是一个Python logging模块的格式化,用于在终端输出日志的颜色 二. 安装 pip inst ...
- swagger 文件上传
单个文件上传的写法: @RequestParam MultipartFile pictures 多个文件上传的写法: @RequestParam String token,@RequestPart(& ...