Error :: " Error creating bean with name" In Spring

Error :: " Error creating bean with name" In Spring

**野蝇服务器日志::** org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为 'customerController' 的 bean 时出错:通过字段 'customerService' 表示的不满足的依赖关系; 由以下原因引起:java.lang.RuntimeException:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为 'customerController' 的 bean 时出错:通过字段 'customerService' 表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: Spring 服务实现代码::

    package com.edifixio.training.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.edifixio.training.dao.CustomerDAO;
import com.edifixio.training.entity.Customer;

@Service
public class CustomerServiceImpl {

    @Autowired
    private CustomerDAO customerDAO;


    @Transactional
    public List < Customer > getCustomers() {
        return customerDAO.getCustomers();
    }


    @Transactional
    public void saveCustomer(Customer theCustomer) {
        customerDAO.saveCustomer(theCustomer);
    }


    @Transactional
    public Customer getCustomer(int theId) {
        return customerDAO.getCustomer(theId);
    }


    @Transactional
    public void deleteCustomer(int theId) {
        customerDAO.deleteCustomer(theId);
    }

}

错误的相关部分是:

No qualifying bean of type 'com.edifixio.training.service.CustomerService' available: expected at least 1 bean which qualifies as autowire candidate

您的服务 CustomerServiceImpl 缺少 implements 部分,永远不会被视为 CustomerService bean。

只需将 class 声明为 :

@Service
public class CustomerServiceImpl implements CustomerService