首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

(札记)IOC Spring 初学逻辑整理(Inversion of control)

2012-09-07 
(笔记)IOC Spring 初学逻辑整理(Inversion of control)(MyEclipse)基本构架-- MyEclipse--Add Spring Ca

(笔记)IOC Spring 初学逻辑整理(Inversion of control)
(MyEclipse)基本构架

--> MyEclipse-->Add Spring Capabilities

在SRC文件夹出现ApplicationContext.xml,在此处Compile.
(Contents)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean name="apple" ref="apple2"></property>
</bean>
</beans>


--> Create new package,Apple

The file (AppleDao,AppleDaoImpl,Apples) must be exist.

AppleDao
AppleDaoImpl --> implements AppleDao --> Apple
AppleDaoImple --> implements AppleDao --> Apple2
Apples
package Apple;

public class Apples {
AppleDao apple;

public AppleDao getApple() {
return apple;
}
         // set method is needed here....
public void setApple(AppleDao apple) {
this.apple = apple;
}

public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}
}

create Main to realize the function:

package Apple;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

public static void main(String[] args) {
BeanFactory beanFactory = new ClassPathXmlApplicationContext("applicationContext.xml");
Apples apple=(Apples)beanFactory.getBean("apples");
apple.add();
}

}

热点排行