Spring整理5 -- 模块的组装
如何实现三个模块良好的切换?
?
配置文件
<beans> <bean id="dao" name="code">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"); } }
?