Spring整理5 -- 模块的组装
来源:互联网 发布:眼镜试戴软件 编辑:程序博客网 时间:2024/04/30 11:43
如何实现三个模块良好的切换?
配置文件
<beans>
<bean id="dao" class="dao.CustomerDao"></bean>
<!-- 将dao装配到DaoCaller内dao属性 -->
<bean id="caller" class="caller.DaoCaller">
<property name="dao">
<ref local="dao"/>
</property>
</bean>
</beans>
程序
package dao;
public interface IDAO {
public boolean login(String account,String password);
}
package dao;
public class StudentDao implements IDAO {
public boolean login(String account, String password) {
System.out.println("Student登陆,账号:" + account + " 密码:" + password);
return false;
}
}
package dao;
public class CustomerDao implements IDAO {
public boolean login(String account, String password) {
System.out.println("Customer登陆,账号:" + account + " 密码:" + password);
return false;
}
}
package caller;
import dao.IDAO;
public class DaoCaller {
private IDAO dao;//设置成为一个属性
public IDAO getDao() {
return dao;
}
public void setDao(IDAO dao) {
this.dao = dao;
}
public void callDao(String account,String password){
dao.login(account, password);
}
}
package main;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import caller.DaoCaller;
public class MainModule {
public static void main(String[] args) {
ApplicationContext context =
new FileSystemXmlApplicationContext("applicationContext.xml");
DaoCaller caller = (DaoCaller)context.getBean("caller");
caller.callDao("111", "34;gd");
}
}
- Spring整理5 -- 模块的组装
- Spring整理系列(02)——spring依赖注入,组装对象之间的依赖关系
- Spring整理1 -- 实现模块的切换
- 使用struts+spring+hibernate组装你的web应用架构
- 使用struts+spring+hibernate组装你的web应用架构
- 使用struts+spring+hibernate组装你的web应用架构
- 使用struts+spring+hibernate组装你的web应用架构
- 从spring源码角度分析循环依赖bean的组装
- JAVA IO 模块的整理
- 构件组装-模型驱动的构件组装
- Spring的七大模块
- Spring的七大模块
- Spring的AOP模块
- Spring的七大模块
- Spring的七大模块
- spring 的七大模块
- Spring的七大模块
- Spring 的七大模块
- 在BSP的.bat文件下設置全局變量方法
- java QQ 群
- Java中static、this、super、final用法
- 在Carbide C++ 2.0 中怎样输出RDebug信息
- ASP.NET2.0 文本编辑器FCKeditor
- Spring整理5 -- 模块的组装
- 解决Gmail Space插件自动跳转问题
- 好好努力,不要变成他。
- C++深度探索系列:智能指针(Smart Pointer) [一] + 阅读注解
- 英雄
- memmove可重叠
- DB Design
- 猎狗的故事—戏说管理(转帖)
- iPhone 各項 framework 整理與說明