使用名称employeeController创建bean时出错。注入自动连接的依赖项失败。无法自动装载领域

时间:2017-06-05 13:40:59

标签: java spring hibernate

来自控制台的错误

 SEVERE: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeController': Injection of autowired dependencies failed;
  nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ram.service.EmployeeService com.ram.controller.EmployeeController.employeeService; 
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeService': Injection of autowired dependencies failed;
  nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.ram.dao.EmployeeDao com.ram.service.EmployeeServiceImpl.employeeDao;
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao': Injection of autowired dependencies failed;

EmployeeController.java

@Controller
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @Qualifier(value="employeeService")
    public void setEmployeeService(EmployeeService employeeService){
        this.employeeService = employeeService;
    }

    @RequestMapping(value = "/employees", method = RequestMethod.GET)
    public String listEmployee(Model model) {
        model.addAttribute("employee", new Employee());
        model.addAttribute("listEmployee", employeeService.listEmployee());
        return "employee";
    }

1 个答案:

答案 0 :(得分:0)

此行最符合日志。不幸的是,日志不完整,因此不清楚EmployeeDao的哪个属性丢失了:

nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao': Injection of autowired dependencies failed;

您要将哪些字段映射到EmployeeDao?因为其中一个找不到,可能没有用@Component标记?