【发布时间】:2014-07-05 15:13:26
【问题描述】:
我正在学习 spring,在我的第一个应用程序中,我有不同的 bean(@Repository,@Service)。现在我读到这些 bean 的默认范围是单例。
我的情况如下,我有两个服务注入同一个 Dao。
@Service
public class MyFirtsServiceImpl implements MyFirtsService{
@Autowired
UserDao userDao
}
@Service
public class MySecondServiceImpl implements MySecondService{
@Autowired
UserDao userDao
}
@Repository
public class UserDao {
//methods to manage the persistence
}
现在我对这种情况有些怀疑。作为 userDao 一个单例 bean,那么在两个服务中注入的 UserDao 的实例是一样的吗?容器如何管理这个?
【问题讨论】: