【Java】整合spring时的错误:but was actually of type ‘com.sun.proxy.$Proxy25‘

but was actually of type ‘com.sun.proxy.$Proxy25’

spring整合mybatis时的错误

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘accountController’: Unsatisfied dependency expressed through field ‘accountService’; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘accountService’ is expected to be of type ‘com.zyg.service.impl.AccountServiceImpl’ but was actually of type’com.sun.proxy.$Proxy25’

其实就是自己迷了在Controller类中定义的accountService定义成AccountServiceImpl 了,改成接口类IAccountService 就好了

错误代码

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountServiceImpl accountService;
    @RequestMapping("/findAll")
    public String findAll(Model model){
        System.out.println("表现层查询信息");
        List<Account> list = accountService.findAll();
        model.addAttribute("list",list);
        return "list";

    }
    @RequestMapping("/save")
    public String save(Account account){
        accountService.save(account);
        return "list";
    }

}

修改过的代码

@Controller
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private IAccountService accountService;
    @RequestMapping("/findAll")
    public String findAll(Model model){
        System.out.println("表现层查询信息");
        List<Account> list = accountService.findAll();
        model.addAttribute("list",list);
        return "list";

    }
    @RequestMapping("/save")
    public String save(Account account){
        accountService.save(account);
        return "list";
    }

}


版权声明:本文为weixin_43185955原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。