在我開始之前,請假設(shè)它pom.xml是完美無缺的。話雖如此,讓我們繼續(xù),我得到的錯誤如下:應(yīng)用程序無法啟動 *************************** 說明:com.sagarp.employee.EmployeeService 中的字段 empDao需要一個無法找到的類型為“com.sagarp.employee.EmployeeDao”的 bean?,F(xiàn)在spring boot application類如下:package com.sagarp;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.context.annotation.ComponentScan;@SpringBootApplication@EnableEurekaClient //this is for eureka which not our concern right now.@ComponentScan(basePackages = "com.sagarp.*") //Included all packagespublic class EmployeeHibernateApplication { public static void main(String[] args) { SpringApplication.run(EmployeeHibernateApplication.class, args); }}該EmployeeService班是如下:package com.sagarp.employee;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;@Servicepublic class EmployeeService { @Autowired private EmployeeDao empDao; // interface public EmployeeDao getEmpDao() { return empDao; } public void setEmpDao(EmployeeDao empDao) { this.empDao = empDao; } //some methods}請注意,這EmployeeDao是一個接口。EmployeeDao 界面如下:public interface EmployeeDao { //Oh! so many methods to I have provided}EmployeeDaoImpl實現(xiàn)EmployeeDao接口的類。public class EmployeeDaoImpl implements EmployeeDao { @Autowired private SessionFactory sessionFactory; //Oh!So many methods I had to implement}我猜EmployeeService是因為@Service它是自動裝配的。我添加了所有包,components以便它掃描并實例化我可能擁有的所有依賴項。但它沒有,因此問題。任何人都可以幫助我解決上述詳細信息的錯誤。如果需要更多詳細信息,請告訴我。
3 回答

MMTTMM
TA貢獻1869條經(jīng)驗 獲得超4個贊
組件掃描搜索使用 Spring Stereotype 注釋注釋的類。為了使類有資格進行自動裝配,它必須具有這些注釋之一。
解決方案是使用@Component、@Service 或@Repository 注釋EmployeeDaoImpl。
添加回答
舉報
0/150
提交
取消