【问题标题】:Error :: " Error creating bean with name" In Spring [closed]错误::“错误创建带有名称的bean”在Spring中[关闭]
【发布时间】:2020-04-02 10:54:02
【问题描述】:

**Wild Fly 服务器日志 :: ** 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);
    }

}

【问题讨论】:

  • 把代码提供给服务很好,但是没有注入的代码,可能很难帮你。

标签: java spring spring-mvc spring-data-jpa spring-jdbc


【解决方案1】:

错误的相关部分是:

没有符合条件的 bean 类型 'com.edifixio.training.service.CustomerService' 可用:预计在 至少 1 个 bean 有资格作为自动装配候选者

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

只需将类声明为:

@Service
public class CustomerServiceImpl implements CustomerService

【讨论】:

    猜你喜欢
    • 2018-08-11
    • 1970-01-01
    • 2021-01-28
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2016-12-15
    相关资源
    最近更新 更多