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"> <!--用于激活容器中注冊(cè)的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ù)庫(kù)基本信息配置 --> <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"/> <!-- 超過(guò)時(shí)間限制是否回收 --> <property name="removeAbandoned" value="true"/> <!-- 超過(guò)時(shí)間限制多長(zhǎng); --> <property name="removeAbandonedTimeout" value="120000"/> <!-- 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉的空閑連接,單位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000"/> <!-- 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="40000"/> <!-- 用來(lái)檢測(cè)連接是否有效的sql,要求是一個(gè)查詢語(yǔ)句--> <property name="validationQuery" value="select 1"/> <!-- 申請(qǐng)連接的時(shí)候檢測(cè) --> <property name="testWhileIdle" value="true"/> <!-- 申請(qǐng)連接時(shí)執(zhí)行validationQuery檢測(cè)連接是否有效,配置為true會(huì)降低性能 --> <property name="testOnBorrow" value="false"/> <!-- 歸還連接時(shí)執(zhí)行validationQuery檢測(cè)連接是否有效,配置為true會(huì)降低性能 --> <property name="testOnReturn" value="false"/> <!-- 打開PSCache,并且指定每個(gè)連接上PSCache的大小 --> <property name="poolPreparedStatements" value="true"/> <property name="maxPoolPreparedStatementPerConnectionSize" value="50"/> <!--屬性類型是字符串,通過(guò)別名的方式配置擴(kuò)展插件,常用的插件有: 監(jiān)控統(tǒng)計(jì)用的filter:stat 日志用的filter:log4j 防御SQL注入的filter:wall --> <property name="filters" value="stat"/> </bean> </beans>
在mappers下邊是mybatis的xml文件,啟動(dòng)的時(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é)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- 如何在ASP.NET Core 的任意類中注入Configuration
- C# 添加對(duì)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后自動(dòng)配置不生效及如何配置攔截器
- 解析SpringBoot @EnableAutoConfiguration的使用
- Spring中基于Java的配置@Configuration和@Bean用法詳解
- @Configuration與@Component作為配置類的區(qū)別詳解
- .NET Core 3.0之創(chuàng)建基于Consul的Configuration擴(kuò)展組件
- SpringBoot 中 AutoConfiguration的使用方法
- Spring源碼解析之Configuration
相關(guān)文章
SpringCloud Nacos作為配置中心超詳細(xì)講解
這篇文章主要介紹了Springcloud中的Nacos作為配置中心,本文以用戶微服務(wù)為例,進(jìn)行統(tǒng)一的配置,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12Java圖片處理 (文字水印、圖片水印、縮放、補(bǔ)白)代碼實(shí)例
這篇文章主要介紹了Java圖片處理 (文字水印、圖片水印、縮放、補(bǔ)白)代碼實(shí)例,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-06-06關(guān)于Java創(chuàng)建線程的2種方式以及對(duì)比
這篇文章主要給大家介紹了關(guān)于Java創(chuàng)建線程的2種方式以及對(duì)比的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-01-01Spring security基于數(shù)據(jù)庫(kù)中賬戶密碼認(rèn)證
這篇文章主要介紹了Spring security基于數(shù)據(jù)庫(kù)中賬戶密碼認(rèn)證,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03詳解Spring Cloud中Hystrix 線程隔離導(dǎo)致ThreadLocal數(shù)據(jù)丟失
這篇文章主要介紹了詳解Spring Cloud中Hystrix 線程隔離導(dǎo)致ThreadLocal數(shù)據(jù)丟失,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03你應(yīng)該知道的這些Mybatis-Plus使用技巧(小結(jié))
這篇文章主要介紹了你應(yīng)該知道的這些Mybatis-Plus使用技巧(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08java使用計(jì)算md5校驗(yàn)碼方式比較兩個(gè)文件是否相同
MD5文件效驗(yàn)碼是一個(gè)判斷文件是否是相同文件的途徑,通過(guò)比較兩個(gè)文件的Md5效驗(yàn)碼是否相同來(lái)精確判斷兩個(gè)文件是否相同2014-04-04