idea 创建的maven+spring+mybatis项目整合 报错无法创建bean

 


最近在做一个由maven构建的spring+mybatis+struts2项目,刚开始的时候是用自己的老电脑Win7环境下的eclipse写的,托管到了码云上面,刚开始什么问题都没有

 

直到某一天在公司的时候无聊想继续写这个项目,于是就把这个项目clone了一份在公司用的电脑上,在公司用的是mac+idea,结果问题就来了,clone下来的代码居然不能运行!!!,各种看着一脸懵逼的报错信息(idea的tomcat运行日志文件很不好找,找了好久)辛辛苦苦弄了一周左右,期间经历了把项目删了又建,然后自己搭环境等各种坑爹的环节,一开始报错信息千奇百怪,在弄了这么久之后大概就稳定成了如下的样子:

 

rk.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.scpchome.dao.UserDao com.scpchome.service.impl.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.scpchome.dao.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in file [/Users/kep/Documents/apache-tomcat-7.0.70/webapps/ROOT/WEB-INF/classes/com/scpchome/dao/UserDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [/Users/kep/Documents/apache-tomcat-7.0.70/webapps/ROOT/WEB-INF/classes/applicationContext-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.core.io.Resource[]' for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/scpchome/dao/mapping/*.xml]: class path resource [com/scpchome/dao/mapping/] cannot be resolved to URL because it does not exist

 

一直是不能创建bean的样子,经过一行一行地阅读报错信息。。最后发现mybatis的映射xml文件居然没有找到,然后又去翻classes目录,结果果然没有,知道具体的错误就好办了,随后百度了一发在pom文件中加入了如下代码,困扰了一周的问题成功解决

 

 

<build>
   

      <resources>
        <!--编译之后包含xml-->
        <resource>
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.xml</include>
          </includes>
          <filtering>true</filtering>
        </resource>
      </resources>

  </build>

 

 

 

 

 

 

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值