zoukankan      html  css  js  c++  java
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bireportSqlSessionFactory' defined in URL

    报错如下:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bireportSqlSessionFactory' defined in URL [file:/D:/devcode/apstart/bireport/bireport-center/target/bireport-center/WEB-INF/classes/spring/spring-bireport-db.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:devcodeapstartireportireport-center	argetireport-centerWEB-INFclassescomapstarireportmapperdemo.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Mapper's namespace cannot be empty

    1.刚开始的时候,怀疑是mybatis的bean有问题,更换了名称,不行。

    2.然后查看资料,尝试在pom里面放入依赖包,但工程发现已经下载有了mybatis的两个包,所以排除。

    3.检查我的mybatis-config.xml配置文件,也没问题,排除。

    4.结果发现:我使用了p:mapperLocations 所以,mybatis会扫描我的mapper的xml文件,如果没有它,会报bean错误

    在我的mapper层下的xml文件,必须要建有,并且是有mybatis的头引用,并且<mapper...><.mapper>内容不能为空。

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
    <mapper namespace="com.apstar.bireport.dao.DemoDao">

    <select id="selectDemo" parameterType="com.apstar.bireport.po.DemoPo"
    resultType="com.apstar.bireport.po.DemoPo"></select>
    </mapper>

    我的mybatis配置如下 :

     <!-- mybatis配置 -->
        <!-- mybatis文件配置,扫描所有mapper文件 -->
        <bean id="bireportSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
              p:dataSource-ref="bireportDataSource" p:configLocation="classpath:mybatis/mybatis-config.xml"
              p:mapperLocations="classpath*:com/apstar/bireport/mapper/*.xml"
              p:typeAliasesPackage="com.apstar.bireport.po"/>
    <!-- mybatisDAO配置 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.apstar.bireport.dao"/> <property name="sqlSessionFactoryBeanName" value="bireportSqlSessionFactory"/> </bean>

      

    参考了:https://blog.csdn.net/ljm15832631631/article/details/79346279

  • 相关阅读:
    AndroidStudio gradle配置
    Git中pull对比fetch和merge
    Knockout.js随手记(7)
    Knockout.js随手记(6)
    MVC自动绑定整数数组
    Knockout.js随手记(5)
    ASP.NET4.5Web API及非同步程序开发系列(3)
    Knockout.js随手记(4)
    ASP.NET4.5Web API及非同步程序开发系列(2)
    ASP.NET4.5Web API及非同步程序开发系列(1)
  • 原文地址:https://www.cnblogs.com/phpli/p/10565874.html
Copyright © 2011-2022 走看看