MyBatis異常-Property 'configLocation' not specified, using default MyBatis Configuration
配置文件如下:

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">
<!-- 數(shù)據(jù)庫基本信息配置 -->
<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}"/>
<!-- 初始化連接數(shù)量 -->
<property name="initialSize" value="10"/>
<!-- 最大并發(fā)連接數(shù) -->
<property name="maxActive" value="100"/>
<!-- 最小空閑連接數(shù) -->
<property name="minIdle" value="20"/>
<!-- 配置獲取連接等待超時(shí)的時(shí)間 -->
<property name="maxWait" value="5000"/>
<!-- 超過時(shí)間限制是否回收 -->
<property name="removeAbandoned" value="true"/>
<!-- 超過時(shí)間限制多長; -->
<property name="removeAbandonedTimeout" value="120000"/>
<!-- 配置間隔多久才進(jìn)行一次檢測,檢測需要關(guān)閉的空閑連接,單位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
<!-- 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="40000"/>
<!-- 用來檢測連接是否有效的sql,要求是一個(gè)查詢語句-->
<property name="validationQuery" value="select 1"/>
<!-- 申請連接的時(shí)候檢測 -->
<property name="testWhileIdle" value="true"/>
<!-- 申請連接時(shí)執(zhí)行validationQuery檢測連接是否有效,配置為true會降低性能 -->
<property name="testOnBorrow" value="false"/>
<!-- 歸還連接時(shí)執(zhí)行validationQuery檢測連接是否有效,配置為true會降低性能 -->
<property name="testOnReturn" value="false"/>
<!-- 打開PSCache,并且指定每個(gè)連接上PSCache的大小 -->
<property name="poolPreparedStatements" value="true"/>
<property name="maxPoolPreparedStatementPerConnectionSize"
value="50"/>
<!--屬性類型是字符串,通過別名的方式配置擴(kuò)展插件,常用的插件有:
監(jiān)控統(tǒng)計(jì)用的filter:stat
日志用的filter:log4j
防御SQL注入的filter:wall -->
<property name="filters" value="stat"/>
</bean>
</beans>
在mappers下邊是mybatis的xml文件,啟動的時(shí)候出現(xiàn)錯(cuò)誤:
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的位置即可,或者所有的文件都在一個(gè)文件即可
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
- 如何在ASP.NET Core 的任意類中注入Configuration
- C# 添加對System.Configuration.dll文件的引用操作
- matplotlib運(yùn)行時(shí)配置(Runtime Configuration,rc)參數(shù)rcParams解析
- mybatis的Configuration詳解
- .Net Core3.0 配置Configuration的實(shí)現(xiàn)
- 詳解@ConfigurationProperties實(shí)現(xiàn)原理與實(shí)戰(zhàn)
- @ConfigurationProperties綁定配置信息至Array、List、Map、Bean的實(shí)現(xiàn)
- 詳解配置類為什么要添加@Configuration注解
- Spring @Configuration注解及配置方法
- Springboot @Configuration @bean注解作用解析
- SpringBoot @ConfigurationProperties使用詳解
- 繼承WebMvcConfigurationSupport后自動配置不生效及如何配置攔截器
- 解析SpringBoot @EnableAutoConfiguration的使用
- Spring中基于Java的配置@Configuration和@Bean用法詳解
- @Configuration與@Component作為配置類的區(qū)別詳解
- .NET Core 3.0之創(chuàng)建基于Consul的Configuration擴(kuò)展組件
- SpringBoot 中 AutoConfiguration的使用方法
- Spring源碼解析之Configuration
相關(guān)文章
教你從頭開始用JAVA創(chuàng)建一個(gè)自己的簡單API并實(shí)現(xiàn)第三方調(diào)用
在日常開發(fā)的時(shí)候,經(jīng)常會遇到需要調(diào)用別人的接口的場景,下面這篇文章主要給大家介紹了關(guān)于如何從頭開始用JAVA創(chuàng)建一個(gè)自己的簡單API并實(shí)現(xiàn)第三方調(diào)用的相關(guān)資料,需要的朋友可以參考下2023-12-12
java阻塞隊(duì)列BlockingQueue詳細(xì)解讀
這篇文章主要介紹了java阻塞隊(duì)列BlockingQueue詳細(xì)解讀,在新增的Concurrent包中,BlockingQueue很好的解決了多線程中,如何高效安全“傳輸”數(shù)據(jù)的問題,通過這些高效并且線程安全的隊(duì)列類,為我們快速搭建高質(zhì)量的多線程程序帶來極大的便利,需要的朋友可以參考下2023-10-10
Spring security實(shí)現(xiàn)記住我下次自動登錄功能過程詳解
這篇文章主要介紹了Spring security實(shí)現(xiàn)記住我下次自動登錄功能過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
解決Springboot啟動報(bào)錯(cuò):類文件具有錯(cuò)誤的版本61.0,應(yīng)為?52.0
這篇文章主要給大家介紹了關(guān)于解決Springboot啟動報(bào)錯(cuò):類文件具有錯(cuò)誤的版本?61.0,應(yīng)為?52.0的相關(guān)資料,這是查閱了網(wǎng)上的很多資料才解決的,分享給大家,需要的朋友可以參考下2023-01-01
idea?maven依賴引入失效無法正常導(dǎo)入依賴問題的解決方法
有時(shí)候idea導(dǎo)入一個(gè)新項(xiàng)目,或者pom文件修改(新增)了依賴,pom文件和代碼會報(bào)紅,提示依賴包不存在,下面這篇文章主要給大家介紹了關(guān)于idea?maven依賴引入失效無法正常導(dǎo)入依賴問題的解決方法,需要的朋友可以參考下2023-04-04
java隊(duì)列中Queue與Deque的區(qū)別面試精講
這篇文章主要為大家介紹了java隊(duì)列中Queue與Deque的區(qū)別面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10

