Web层
public class test01 {
public static void main(String[] args) {
ApplicationContext app =
new ClassPathXmlApplicationContext("applicationContext.xml");
// UserDao userDao = (UserDao) applicationContext.getBean("userDao");
// userDao.save();
UserService userService = (UserService) app.getBean("userService");
userService.serv();
}
}
Service层
@Component("userService")
public class UserServiceImpl implements UserService {
@Autowired
@Qualifier("userDao")
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
public void serv() {
userDao.save();
}
}
Daon层
@Component("userDao")
public class UserDaoImpl implements UserDao {
public void save() {
System.out.println("你好世界");
}
} |
|