admin管理员组文章数量:1530266
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";
}
}
版权声明:本文标题:【Java】整合spring时的错误:but was actually of type ‘com.sun.proxy.$Proxy25‘ 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726602273a1077174.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论