开发者社区> 问答> 正文

springMVC spring3.1+ mybatis3.1+?报错

求一份整合spring3.1 springMVC 和mybatis  的详细说明文档或者代码。自己整合几天了 ,

controller 没问题 能转发请求就是 整合mybatis 在controller 加上@Inject
private UserService userService;  后 启动就报错 


Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.blue.service.UserService com.blue.controller.LoginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.blue.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}


求指教

展开
收起
爱吃鱼的程序员 2020-06-22 20:40:26 445 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    mybatis 的例子中貌似有额!
    有问题可以联系我,几个版本我都用过

    nomatchingbeanoftype[com.blue.service.UserService]
    你的UserService没有添加到Spring的容器中吧?

    回复<aclass='referer'target='_blank'>@foeget:Spring报的是没有这个类,就不存在应该不应该的。建议最好把log改成debug,看下是否有正确加载你的服务类到容器中。用的注解实现类用的<aclass='referer'target='_blank'>@service扫描包路径应该没问题没这困难吧看来你整合经验少了前年整过后来用工作流 <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:normal;background-color:#FFFFFF;">mybatis又换ibatis了在注解的时候用@Controller,<aclass='referer'target='_blank'>@Service,<aclass='referer'target='_blank'>@Resource那spring说的就是没有这样的bean需要注入。仔细检查下,很容易遗漏的用了白搭肯定注解错了bean肯定存在没有被spring容器管理初始化的

    Spring3.2 

    <spanstyle="line-height:1.5;font-size:10pt;">Controller中这样声明

    <spanstyle="line-height:1.5;font-size:10pt;">@Autowired

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">privateUserServiceuserService; 

    <spanstyle="font-size:14px;line-height:22px;">springxml 能找到类

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><context:component-scanbase-package="xxx.xx"/>

    service和dao加载没问题了就是maperr接口不能映射到配置文件 没法容器生成实现类

    在dao层引用mapper接口还是报错

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">com.blue.controller.LoginController.userService 小写?<context:component-scanbase-package="xxx.xx"/>加上这句配置在UserService上加@Service("userService"),然后再conroller中的UserService上加@AutoWired试试@InjectprivateUserServiceuserService;

    2020-06-22 20:40:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多