SpringBoot整合Mybatis時無法掃描Mapper問題
使用mybatis官方提供的starter與SpringBoot做整合
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
在IDE中啟動專案沒有問題,但當打成JAR啟動專案時出現以下異常:
15 :51:43.909 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean found for dependency [org.zbt.service.jxc.dao.base.DataDicMapper]: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework .beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1463)
............
org.springframework.boot.starter.dubbo.startup.BootStrap.main(BootStrap.java:15)
2016-11-13 15:51:44.389 ERROR 3349 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter
由異常可以知道是因為Mapper沒有SpringBoot掃描到。
而官方提供的可配置引數只有以幾個:
config-location MyBatis xml config file (optional)
mapper-locations Mapper xml config files (optional)
type-aliases-package Package to search for type aliases (optional)
type-handlers-package Package to search for type aliases (optional)
executor-type Executor type: SIMPLE, REUSE, BATCH (optional)
configuration A MyBatis Configuration bean
可以看出無法指定Mapper介面的位置。
可以通過在可以被SpringBoot載入到的spring檔案中加入以下配置來解決這一個問題:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name="basePackage" value="org.zbt.service.jxc.dao.base"/>
<property name="annotationClass" value="org.apache.ibatis.annotations.Mapper"/>
</bean>
相關推薦
SpringBoot整合Mybatis時無法掃描Mapper問題
使用mybatis官方提供的starter與SpringBoot做整合 <dependency> <groupId>org.mybatis.spring.boot</groupId>
springboot整合mybatis遇到無法掃描MaperScan包的問題
cti exceptio start leg inter 3.1 clip main app 1.啟動類加上@MaperScan註解後,一直報錯如下: Error creating bean with name ‘platUserMapper‘ defined in fil
idea中springboot整合mybatis找不到mapper介面的原因及解決方法
整合網上以及開發時遇到的錯誤原因總結:路徑不對 1.maper.xml名稱空間不對應mapper介面的位置 2.xml方法名未對應上mappe接口裡面的方法名 、 3.mapper檔案未注入成功,也就是位置掃描錯誤。 4.如果都檢查完了,一定要檢查編譯後的檔
SpringBoot整合Mybatis 時開啟事務
1、首先在啟動類加上 @EnableTransactionManagement(proxyTargetClass = true) 注:proxyTargetClass預設為false,springboot的事務是以 JDK dynamic proxy 實現的。我不加之前
SpringBoot 整合Mybatis時控制檯輸出sql語句
SpringBoot整合Mybatis極大的加快了開發速度。但是時間長了發現一個問題,sql不論執行的錯與對,控制檯都看不到當前執行的sql資訊,多有不便。 在application.yml進行以下配置即可: logging: level: com.sicme
spring整合mybatis,批量掃描mapper接口出現異常
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:\Java\eclipse-workspace2\spring_my
Spring Boot 整合mybatis時遇到的mapper接口不能註入的問題
應該 mapper 設置 註解 通過 per 註入 spring容器 否則 現實情況是這樣的,因為在練習spring boot整合mybatis,所以自己新建了個項目做測試,可是在idea裏面mapper接口註入報錯,後來百度查詢了下,把idea的註入等級設置為了warni
Spring Boot 整合Mybatis時,mapper一直無法注入
今天在使用spring boot整合mybatis時一直無法注入mapper,不管怎麼配置註解掃描包等,都不行,移動了Application這個類也不行。後來發現了應該不是Spring Boot掃描包的問題,因為我不管怎麼配置,改程式碼除錯都會報那個錯,於是去pom.xml檔
Maven專案中,關於Spring Boot 整合MyBatis時,Service層無法找到mapper介面的問題解決
mybatis: mapperlocations: classpath:com/xxx/xxx/dao/mapper/*.xml -----掃描對映檔案 config-location: classpath:mybatis-config.xml ------掃描配置檔案注意:路徑要以/ 分割3 M
springboot整合mybatis mapper注入時顯示could not autowire的解決
springboot整合mybatis mapper注入時顯示could not autowire的錯誤,不影響使用,但是看著不爽,如下圖: 解決方法,在mapper加一個註解。如下圖所示: @
SpringBoot整合Mybatis掃描不到Mapper的問題
閒來無事,想學學springboot,開始搭建一個專案,但是一直顯示mapper掃描不到的錯誤: “Exception encountered during context initialization - cancelling refresh attem
Spring整合MyBatis (使用掃描包配置mapper代理)
4.0 ike 生日 exce ini idl XML lis address Spring整合MyBatis (使用掃描包配置mapper代理) pojo是根據表生成的實體類,屬性名要跟字段名相同,不相同sql語句查詢時用別名。 首先導jar包 實體類 public cl
springboot 整合mybatis mapper繫結問題
在pom.xml中的build節點中 新增如下程式碼 <resources> <resource> <directory>src/main/java</directory>
使用spring整合mybatis時,通過spring載入的mapper操作怎麼回滾
1 錯誤程式碼: try{ ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
springboot 整合mybatis,mapper介面和對應的mapper對映檔案放在同一個包下的配置
一、springboot整合mybatis後,需要進行幾個步驟的配置: 1、mapper包下的mapper介面都需要新增@Mapper註解。 2、啟動類上面新增@MapperScan(basepackages={"com.web.mapper"})註解。 3、需要在po
SpringBoot整合MyBatis、PageHelper和通用Mapper
之前一直用SSM框架,今天嘗試了一下將MyBatis、PageHelper和通用Mapper進行整合,所以將整合過程記錄作為後續檢視之用。 Mybatis-PageHelper的說明介紹可以點選這裡,一些配置引數與使用介紹可以點選這裡檢視,我在整合這些外掛的時
SpringBoot整合Mybatis-通用mapper使用二級快取
未使用二級快取前測試 執行了三條sql: 開啟二級快取 在yml檔案中: 在Mapper介面上使用@CacheNamespace註解: 資料庫entity需要序列化: 測試: 執行結果: 發現只執行了一條sql,後面兩條sql會
springboot整合Mybatis 配置通用Mapper
按照網上部落格上寫的加上了pom依賴後,啟動之後呼叫通用Mapper的方法就會報BaseSelectProvider無法初始化的錯。 百度一番之後解決方法如下: pom依賴: <dependency> <groupId>t
關於SpringBoot整合Mybatis整合時遇到的/文件根元素 "beans" 必須匹配 DOCTYPE 根 "null"/問題
這個問題應該是剛學習spring boot的同學經常遇到的,也困惑了我一晚上。 遇到這個問題的原因有很多種,所以解決方式不同,我這裡說下我遇到的情況和解決辦法。 先說我遇到的情況的解決辦法,就是新增下面標紅的一句,把Spring XML配置檔案主動引入,你如果是相同的問題,可以去自己的專案裡
Springboot整合shiro時出現的靜態資源無法訪問的問題
使用Springboot整合shiro之後,我的靜態資源竟然不見了,講真,第一次整合shiro,完全不知道是什麼原理怎麼辦,百度原來是shiro把它給攔截了,找了很多文章,整了一堆話,都不是我想要的,後來看到一篇文章,一語中的http://412887952-qq-com.i