当前位置: 首页 > 知识库问答 >
问题:

创建名为“accountController”的bean时出错:通过字段“accountService”表示的未满足的依赖项

丁曦哲
2023-03-14

我查了一些类似的问题,但这些答案帮不了我。

错误

组织。springframework。豆。工厂未满足的依赖项异常:创建名为“accountController”的bean时出错:未满足的依赖项通过字段“accountService”表示;嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException:没有类型为“com”的合格bean。服务AccountService'可用:至少需要1个符合autowire候选资格的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

会计控制

package com.controller;
import com.domain.Account;
import com.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/save",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String save(Account account){
        accountService.save(account);
        return "save success";
    }

    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        List<Account> accountList = accountService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accountList",accountList);
        modelAndView.setViewName("accountList");
        return modelAndView;
    }

}

AccountServiceImpl

package com.service.impl;

import com.domain.Account;
import com.mapper.AccountMapper;
import com.service.AccountService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Service("accountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public void save(Account account) {
        accountMapper.save(account);
    }

    @Override
    public List<Account> findAll() {
        return accountMapper.findAll();
    }
}

会计服务

package com.service;

import com.domain.Account;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public interface AccountService {

    public void save(Account account);

    public List<Account> findAll();
}

共有1个答案

韦嘉颖
2023-03-14

我相信com。在@springboot应用程序设置中未扫描服务

 类似资料: