整合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";
    }

}

发布了1 篇原创文章 · 获赞 0 · 访问量 9
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览