我有一个接口(interface)名称
public interface ScoreDao {
public int storeScore(OverallScore overallScore);
public void storeIndividualScore(ScoreTO scoreTO);
}
实现类如下
@Repository("scoreDao")
public class ScoreDaoImpl implements ScoreDao {
@Override
public int storeScore(OverallScore overallScore) {
//Implementation
}
@Override
public void storeIndividualScore(ScoreTO scoreTO){
//Implementation
}
}
来电者正在使用如下服务
@Service("scoreService")
public class scoreServiceImpl implements IScoreService {
@Autowired
private ScoreDao scoreDao;
@Override
public int storeScore(OverallScore overallScore) {
return scoreDao.storeOverallScore(overallScore);
}
@Override
public void storeIndividualScore(ScoreTO scoreTO) {
scoreDao.storeIndividualScore(scoreTO);
}
}
我正在使用 spring 4.x,在部署时出现如下 bean 冲突错误。
Caused by: java.lang.RuntimeException: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'ScoreDao' for bean class [ScoreDao] conflicts with existing, non-compatible bean definition of same name and class [ScoreDaoImpl]
当我将接口(interface)名称更改为 IScoreDao 时,它可以正常工作。是因为服务名@Repository("scoreDao") 和接口(interface)名一样吗?
最佳答案
简单的答案是是,这是因为您有一个名为ScoreDao
的接口(interface),并且您将其实现为@Repository("scoreDao ")
两种解决方法:
将
ScoreDao
重命名为其他名称将
@Repository("scoreDao")
更改为@Repository
以便它将使用默认名称
关于java - Spring 服务名称与接口(interface)名称冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50678002/