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

所属分类: 软件编程 / java 阅读数: 41
收藏 0 赞 0 分享

配置文件如下:

base-context.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <!--用于激活容器中注册的bean-->
  <!--<context:annotation-config/>-->
  <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如下:

<?xml version="1.0" encoding="UTF-8"?>
<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文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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"/>
    <!-- 用来检测连接是否有效的sql,要求是一个查询语句-->
    <property name="validationQuery" value="select 1"/>
    <!-- 申请连接的时候检测 -->
    <property name="testWhileIdle" value="true"/>
    <!-- 申请连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
    <property name="testOnBorrow" value="false"/>
    <!-- 归还连接时执行validationQuery检测连接是否有效,配置为true会降低性能 -->
    <property name="testOnReturn" value="false"/>
    <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
    <property name="poolPreparedStatements" value="true"/>
    <property name="maxPoolPreparedStatementPerConnectionSize"
         value="50"/>
    <!--属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
        监控统计用的filter:stat
        日志用的filter:log4j
        防御SQL注入的filter:wall -->
    <property name="filters" value="stat"/>
  </bean>
</beans>

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

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

解决方式如下:

<bean 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"/>
</bean>

在sessionFactory下加入:

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

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

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接

更多精彩内容其他人还在看

java实现背单词程序

这篇文章主要为大家详细介绍了java实现背单词程序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

java实现单词查询小程序

这篇文章主要为大家详细介绍了java实现单词查询小程序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Java程序开发环境配置图文教程

这篇文章主要为大家详细介绍了Java程序开发环境配置图文教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

详解ssh框架原理及流程

在本文中小编给大家整理的是关于ssh框架原理及流程的相关知识点内容,有此需要的朋友们可以学习下。
收藏 0 赞 0 分享

Java实现弹窗效果的基本操作

这篇文章主要为大家详细介绍了Java实现弹窗效果的基本操作,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

详解springmvc常用5种注解

在本篇里我们给大家总结了关于springmvc常用5种注解相关知识点以及实例代码,需要的朋友们参考下。
收藏 0 赞 0 分享

Java实现弹窗效果的基本操作(2)

这篇文章主要为大家详细介绍了Java实现弹窗效果的基本操作第二篇,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Spring Boot假死诊断实战记录

这篇文章主要给大家介绍了关于Spring Boot假死诊断的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Spring Boot具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
收藏 0 赞 0 分享

Java计时新姿势StopWatch详解

这篇文章主要介绍了Java计时新姿势StopWatch,最近公司来了个大佬,从他那里学到不少东西,其中一个就是计时的新姿势「StopWatch」,需要的朋友可以参考下
收藏 0 赞 0 分享

java实现点击按钮弹出新窗体功能

这篇文章主要为大家详细介绍了java实现点击按钮弹出新窗体功能,旧窗体不进行操作,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享
查看更多