在創(chuàng)建使用 Hibernate 作為 ORM 將對(duì)象保存在數(shù)據(jù)庫中的服務(wù)時(shí),我無法啟動(dòng)該應(yīng)用程序。我正在使用 Spring Boot 和 Hibernate。我的服務(wù)實(shí)現(xiàn):@Servicepublic class PropertyServiceImpl implements PropertyService{private PropertyDAO propertyDAO; public PropertyServiceImpl(){ System.out.println("inside propertyserviceimpl constructor");}@Autowiredpublic PropertyServiceImpl(PropertyDAO propertyDAO){ this.propertyDAO = propertyDAO; System.out.println("inside save");}@Transactionalpublic void save(Property property) { propertyDAO.save(property);}@Overridepublic List findAll() { // TODO Auto-generated method stub return null;}}PropertyDAO.javapublic interface PropertyDAO {public void save(Property property); }PropertyDAOImpl 實(shí)現(xiàn) DAOpublic class PropertyDAOImpl implements PropertyDAO{@Autowiredprivate SessionFactory sessionFactory;public void save(Property property) { Session currentSession = sessionFactory.getCurrentSession(); currentSession.saveOrUpdate(property);}}當(dāng)我啟動(dòng) SpringBoot 應(yīng)用程序時(shí),收到以下錯(cuò)誤消息。***************************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.
2 回答

千巷貓影
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
將@Repository添加到您的 DAO 實(shí)現(xiàn)類中,以便可以找到它:
@Repository public?class?PropertyDAOImpl?implements?PropertyDAO?{
實(shí)現(xiàn)傳統(tǒng) Java EE 模式(例如“數(shù)據(jù)訪問對(duì)象”)的團(tuán)隊(duì)也可以將此構(gòu)造型應(yīng)用于 DAO 類,但在此之前應(yīng)注意了解數(shù)據(jù)訪問對(duì)象和 DDD 樣式存儲(chǔ)庫之間的區(qū)別。

慕少森
TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
按如下方式更改您的 PropertyDAO:
public interface PropertyDAO extends JpaRepository<Property, Integer>{ }
添加回答
舉報(bào)
0/150
提交
取消