【发布时间】:2019-07-01 09:51:49
【问题描述】:
我在尝试运行我的应用时遇到以下错误:
com.alon.service.EmployeeServiceImpl 中的字段 edao 需要一个 bean 键入找不到的“com.alon.repository.EmployeeRepository”。
注入点有如下注解:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
行动:
考虑定义一个 bean 类型 'com.alon.repository.EmployeeRepository' 在您的配置中。
项目结构:
EmployeeRepository:
package com.alon.repository;
import com.alon.model.Employee;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface EmployeeRepository {
List<Employee> findByDesignation(String designation);
void saveAll(List<Employee> employees);
Iterable<Employee> findAll();
}
EmployeeServiceImpl:
package com.alon.service;
import com.alon.model.Employee;
import com.alon.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EmployeeServiceImpl implements EmployeeService {
@Autowired
private EmployeeRepository edao;
@Override
public void saveEmployee(List<Employee> employees) {
edao.saveAll(employees);
}
@Override
public Iterable<Employee> findAllEmployees() {
return edao.findAll();
}
@Override
public List<Employee> findByDesignation(String designation) {
return edao.findByDesignation(designation);
}
}
我的应用程序:
package com.alon;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplicataion {
public static void main(String[] args) {
SpringApplication.run(MyApplicataion.class, args);
}
}
【问题讨论】:
-
如果没有实现,
EmployeeRepository将不可用。创建一个实现。
标签: java spring spring-boot spring-data-elasticsearch