【发布时间】:2019-09-08 05:36:01
【问题描述】:
在创建将使用 Hibernate 作为 ORM 将对象保存在数据库中的服务时,我无法启动应用程序。
我正在使用 Spring Boot 和 Hibernate。我的服务实现:
@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 实现 DAO
public class PropertyDAOImpl implements PropertyDAO{
@Autowired
private SessionFactory sessionFactory;
public void save(Property property) {
Session currentSession = sessionFactory.getCurrentSession();
currentSession.saveOrUpdate(property);
}
}
我在启动 SpringBoot 应用程序时收到以下错误消息。
***************************
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.
【问题讨论】:
-
显示未找到的
PropertyDAO类 -
用 PropertyDAO 更新了问题
-
但是标记为 Spring bean 并实现该 PropertyDAO 接口的具体类在哪里?
-
PropertyDAOImpl 实现 PropertyDAO
-
但它是 Spring bean 吗?它是否具有将其标记为 Spring bean 的 Component 注释(或 Service 注释或 Repository 注释)? Spring 只注入 Sring bean。不是随机课程。
标签: java spring hibernate spring-boot