MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration

配置文件如下:

MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration_第1张图片

base-context.xml文件如下:


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    
    

    <context:property-placeholder location="classpath*:/props/*.properties" ignore-unresolvable="true"/>

    <context:component-scan base-package="com.ufind.server.*">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    context:component-scan>
beans>

db-mybatis.xml如下:


<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"/>
    bean>

    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ufind.server.infra.repository.sql"/>
        <property name="sqlSessionFactoryBeanName" value="sessionFactory"/>
    bean>
beans>

persistence-context.xml文件如下:


<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dataSourceTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    bean>

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          init-method="init" destroy-method="close">
        
        <property name="driverClassName" value="${db.jdbc.driver}"/>
        <property name="url" value="${db.jdbc.connection.url}"/>
        <property name="username" value="${db.jdbc.username}"/>
        <property name="password" value="${db.jdbc.password}"/>
        
        <property name="initialSize" value="10"/>
        
        <property name="maxActive" value="100"/>
        
        <property name="minIdle" value="20"/>
        
        <property name="maxWait" value="5000"/>
        
        <property name="removeAbandoned" value="true"/>
        
        <property name="removeAbandonedTimeout" value="120000"/>
        
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        
        <property name="minEvictableIdleTimeMillis" value="40000"/>
        
        <property name="validationQuery" value="select 1"/>
        
        <property name="testWhileIdle" value="true"/>
        
        <property name="testOnBorrow" value="false"/>
        
        <property name="testOnReturn" value="false"/>
        
        <property name="poolPreparedStatements" value="true"/>
        <property name="maxPoolPreparedStatementPerConnectionSize"
                  value="50"/>
        
        <property name="filters" value="stat"/>
    bean>
beans>

在mappers下边是mybatis的xml文件,启动的时候出现错误:

DEBUG o.m.spring.SqlSessionFactoryBean - Property 'configLocation' not specified, using default MyBatis Configuration

MyBatis异常-Property 'configLocation' not specified, using default MyBatis Configuration_第2张图片

解决方式如下:

 id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:mybatis/mappers/*.xml"/>
        <property name="configLocation" value="classpath:spring/persistence-context.xml"/>
    

在sessionFactory下加入:

<property name="configLocation" value="classpath:spring/persistence-context.xml"/>

添加persistence-context.xml的位置即可,或者所有的文件都在一个文件即可

你可能感兴趣的:(Mybatis)