@Autowired原理
例子、
// <bean id="> id默认类名首字母小写 默认是单例
// @Scope(value = "prototype")
@Repository
public class UserDao extends BaseDao<User> {
@Override
public void save() {
System.out.println("UserDao...保存用户....");
}
}
@Service
public class UserService {
// 自动装配,自动的为这个属性赋值
@Autowired
private UserDao userDao;
public void save(){
userDao.save();
}
}
@Service
public class UserServiceExt extends UserService {
@Autowired
private UserDao userDao;
@Override
public void save() {
System.out.println("userServiceExt.......");
}
}
@Controller
public class UserController {
// Qualifier:指定一名作为id,让spring别使用变量名作为id
@Qualifier("userService")
@Autowired
private UserService userServiceExt2;
public void save(){
userServiceExt2.save();
}
}