笔记-spring 注入
来源:互联网 发布:python初学者看什么书 编辑:程序博客网 时间:2023/03/30 15:30
package com.dora.testingPerson.bean;import com.dora.testingPerson.ibean.Axe;import com.dora.testingPerson.ibean.Person;public class American implements Person {String americanName = null;Axe axe = null;public void setAmericanName(String name) {this.americanName = name;}public void setAxe(Axe axe) {this.axe = axe;}public void useAxe() {// TODO Auto-generated method stubSystem.out.println("hello, my name is "+this.americanName + ". " + axe.chop());}}
ExampleBean类
package com.dora.testingPerson.bean;import com.dora.testingPerson.ibean.Person;public class ExampleBean {private American person = new American();public Person getPerson() {return this.person;}}
ExampleBean有一个成员对象是American
applicationContext.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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-3.0.xsd"><bean id="stealaxe" class="com.dora.testingPerson.bean.StealAxe" > <property name="helloWord" value="a steal axe is helpful in the wild!" /></bean> <bean id="exampleBean" class="com.dora.testingPerson.bean.ExampleBean"> <property name="person.americanName" value="孙悟空" /> <property name="person.axe" ref="stealaxe" /> </bean></beans>
Spring要先调用ExampleBean的getPerson方法先去的American的实例子,再调用American的setAmericanName和setAxe方法。
所以,ExampleBean方法一定要提供一个getPerson方法,spring才能给americanName和axe赋值。
- 笔记-spring 注入
- Spring 学习笔记 ----依赖注入
- [学习笔记]Spring依赖注入
- 学习笔记:Spring注解注入
- Spring学习笔记 依赖注入
- 【Spring学习笔记】依赖注入
- [Spring开发笔记]Spring 集合注入详解
- Spring学习笔记(4.Spring注入)
- 【Spring笔记】(二)集合注入、注入的方法
- 《Pro Spring》学习笔记之集合注入
- Spring学习笔记-注入实战篇
- spring温习笔记-入门-依赖注入
- spring学习笔记3--依赖注入对象
- spring学习笔记(5)--集合注入
- Spring学习笔记(1)---依赖注入
- Spring笔记(5)------依赖注入
- Spring笔记(6)-----------注入参数详解
- Spring笔记(7)------方法注入
- 求n阶幻方的一种算法实现C/C++
- NULL指针、零指针、野指针
- 为什么 javascript 中 0.1 + 0.2 !== 0.3 为 True
- codefroces 2B The least round way
- FusionCharts Free中文开发指南 第十二章--FCF中的特殊字符
- 笔记-spring 注入
- ArcGIS JavaScript API本地部署离线开发环境
- http://www.slideshare.net
- C++的一些基本知识,不会会抓狂
- PCB设计注意事项
- 三层架构中使用实体类填充泛型集合代替DataTable解决方案(ASP.NET+C#)
- oracle导入导出
- linux音频alsa-uda134x驱动分析之三(解码器)
- git revert 和reset的区别