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文件中加入了如下代码,困扰了一周的问题成功解决


   

      
        
        
          src/main/java
          
            **/*.xml
          
          true
        
      

  



你可能感兴趣的:(杂项)