1. 次の内容で User.java を作成します:
package net.model; /** * @项目名:spring2.5 * @包名:net.model * @文件名:User.java * @日期:Jun 22, 2011 4:31:22 PM * @备注: * @作者:apple */ public class User { private String username; private String password; public String getUsername() {return username;} public void setUsername(String username) {this.username = username;} public String getPassword() {return password;} public void setPassword(String password) { this.password = password; } }
2. 以下の内容で UserDao.java を作成します:
package net.dao; import net.model.User; /** * @项目名:spring2.5 * @包名:net.dao * @文件名:UserDao.java * @日期:Jun 22, 2011 4:12:42 PM * @备注: * @作者:apple */ public interface UserDao { public void save(User u); }
4. 次の内容で UserDaoImpl.java を作成します。次の内容:
package net.dao.impl; import net.dao.UserDao; import net.model.User; /** * @项目名:spring2.5 * @包名:net.dao.impl * @文件名:UserDaoImpl.java * @日期:Jun 22, 2011 4:13:45 PM * @备注: * @作者:apple */ public class UserDaoImpl implements UserDao { public void save(User u) { // TODO Auto-generated method stub System.out.println("user save..."); } }
5. 次の内容で BeanFactory.java を作成します:
package net.service; import net.dao.UserDao; import net.dao.impl.UserDaoImpl; import net.model.User; /** * @项目名:spring2.5 * @包名:net.service * @文件名:UserService.java * @日期:Jun 22, 2011 4:15:47 PM * @备注: * @作者:apple */ public class UserService { private UserDao userDao ; public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; } public void add(User u){ userDao.save(u); }//这里可以调用任务实现了UserDao接口的save方法了。 }
6. 次の内容で ClassPathXmlApplicationContext.java を作成します:
package net.factory; /** * @项目名:spring2.5 * @包名:net.factory * @文件名:BeanFactory.java * @日期:Jun 22, 2011 4:37:08 PM * @备注: * @作者:apple */ public interface BeanFactory { public Object getBean(String name); }
7. 次の内容で beans.xml を作成します。