java - Parameter 0 of constructor in ServiceImpl required a bean of type DAO that could not be found
问题描述
While creating a service that will save the object in the DB using Hibernate as ORM, I'm unable to start the application.
I'm using Spring Boot and Hibernate. My ServiceImpl:
@Service
public class PropertyServiceImpl implements PropertyService{
private PropertyDAO propertyDAO;
public PropertyServiceImpl(){
System.out.println("inside propertyserviceimpl constructor");
}
@Autowired
public PropertyServiceImpl(PropertyDAO propertyDAO){
this.propertyDAO = propertyDAO;
System.out.println("inside save");
}
@Transactional
public void save(Property property) {
propertyDAO.save(property);
}
@Override
public List findAll() {
// TODO Auto-generated method stub
return null;
}
}
PropertyDAO.java
public interface PropertyDAO {
public void save(Property property);
}
PropertyDAOImpl implement the DAO
public class PropertyDAOImpl implements PropertyDAO{
@Autowired
private SessionFactory sessionFactory;
public void save(Property property) {
Session currentSession = sessionFactory.getCurrentSession();
currentSession.saveOrUpdate(property);
}
}
I'm getting the following error message when I start the SpringBoot Application.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.flarow.flarowhomes.services.PropertyServiceImpl required a bean of type 'com.flarow.flarowhomes.dao.PropertyDAO' that could not be found.
Action:
Consider defining a bean of type 'com.flarow.flarowhomes.dao.PropertyDAO' in your configuration.
解决方案
将@Repository添加到您的 DAO 实现类中,以便找到它:
@Repository
public class PropertyDAOImpl implements PropertyDAO {
实现传统 Java EE 模式(如“数据访问对象”)的团队也可以将此原型应用于 DAO 类,但在这样做之前应注意了解数据访问对象和 DDD 样式存储库之间的区别。
推荐阅读
- phpstorm - 如何在 PhpStorm 中的选项卡之间切换?
- apache-flink - 如何在纱线模式下运行 flink scala shell
- ios - 如何在 UITableview DataSource 方法中的 UIContextualAction 中添加图像
- c++ - 为什么 `operator<<` 对指向派生类型的成员不起作用?
- html - 如何使用表格在模态文本框
- android - 图书馆项目:如何覆盖属性?
- sql - SSRS 报告。在下拉参数中全选
- angular - Angular 6 通信子级 - 具有 ng 内容的父级
- mysql - 从 RDS 快照中使现有用户无效并在从快照创建新实例时创建新用户
- javascript - 如何在javascript中将图像源文件信息添加到另一个数组中的新数组中