1. 程式人生 > >SpringBoot Mybatis注入異常

SpringBoot Mybatis注入異常

    這幾天在研究Spring Boot框架,早Spring Boot和Mybaits結合的時候,我在Action層面住入Service的程式碼沒有報錯,但是在Service注入Mybatis的Mapper介面的時候,報瞭如下的錯誤。

java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
[ERROR] 09:51:11 o.s.boot.SpringApplication => Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iUserService': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.company.test.dao.UserMapper 
com.company.test.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [com.company.test.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for 
this dependency.
 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues
(AutowiredAnnotationBeanPostProcessor.java:334)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
	at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
	at com.company.test.Application.main(Application.java:19)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field:
 private com.company.test.dao.UserMapper com.company.test.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory
.NoSuchBeanDefinitionException: No qualifying bean of type [com.company.test.dao.UserMapper] found for dependency: expected at least 1 bean which 
qualifie
s as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject
(AutowiredAnnotationBeanPostProcessor.java:573)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues
(AutowiredAnnotationBeanPostProcessor.java:331)
錯誤提示

UserMapper的介面沒有實現類,然後我就看了  我的Spring與Mybatis的Jar包也引入了,配置也配置了,怎麼會報這樣的錯誤。


解決方法:

後來發現Spring Boot的main啟動方法,預設掃描的是當前包下的子包類,而我的base專案和test專案包的路徑不對,當我修改包路徑後,

Spring Boot就可以自動掃描到配置檔案,Mapper同時也注入了。

相關推薦

SpringBoot Mybatis注入異常

    這幾天在研究Spring Boot框架,早Spring Boot和Mybaits結合的時候,我在Action層面住入Service的程式碼沒有報錯,但是在Service注入Mybatis的Mapper介面的時候,報瞭如下的錯誤。 java.lang.Object.

理解使用SpringBoot+Mybatis時,並發請求API時報指針異常

content ota cut nal reflect char point wrap ble 問題描述 使用SpringBoot+Mybatis作為後端框架,在前端同時請求兩個及以上API時,後臺會拋出空指針異常。 具體異常信息如下: org.apache.ib

企業分布式微服務雲SpringCloud SpringBoot mybatis (五)Spring Boot中Web應用的統一異常處理

src one exception learn 微服務 public .net 可能 訪問 我們在做Web應用的時候,請求處理過程中發生錯誤是非常常見的情況。Spring Boot提供了一個默認的映射:/error,當處理中拋出異常之後,會轉到該請求中處理,並且該請求有一個

基於SpringBoot+Mybatis開發的簡單異常處理器(ExceptionHandle)

需求: 按照一個人的ID確認他的年齡,如果小於18歲則太年輕,大於65歲則年紀太大。 構思: 一個Person類,按照id查詢Person的age屬性,並對查找出來的age進行判斷。 1.如果年紀小於18,則出現異常“你太年輕”; 2.如果年紀大於65,則出現異常“你

SpringBoot+mybatis 異常報錯org.apache.ibatis.binding.BindingException

之前搭建過Springboot專案沒事,但昨天搭建的一個專案總是報錯而且一直報的是 org.apache.ibatis.binding.BindingException 異常,其他的都能執行,扯了一天,各種辦法都找遍了,就是無法解決。網上對於這一問題的解決方案說來說去就是這幾種 1.包名

MyBatis與Druid資料庫連線池整合監控統計後WallFilterSQL注入異常問題處理方案

資料庫連線池使用的是阿里巴巴的Druid(德魯伊)。專案中啟用了Druid的統計管理,在執行批量修改時提示;Caused by: java.sql.SQLException: sql injection violation, multi-statement not allow

SpringBoot異常:IDEA+SpringBoot+Mybatis使用generatorConfig.xml生成xml,Maven打包異常

IDEA+SpringBoot+Mybatis專案,使用generatorConfig.xml生成xml在Maven打包的時候出現異常在maven package打包時,竟然運行了generatorConfig.xml,把已經修改的java類和xml原件覆蓋掉了,導致問題出現

基於SpringBoot + Mybatis實現 MVC 項目

myba ces find json格式 see framework pro select .info 1.預覽: (1)完整項目結構 (2) 創建數據庫、數據表: 【user.sql】 SET FOREIGN_KEY_CHECKS=0;

第九章 springboot + mybatis + 多數據源 (AOP實現)

app aps 基礎上 default round mapper lan efault epo 在第八章 springboot + mybatis + 多數據源代碼的基礎上,做兩點修改 1、ShopDao package com.xxx.firstboot.da

SpringBoot (七) :springboot + mybatis 多數據源最簡解決方案

註入 upd lec nco action res driver java 不同 原文出處: 純潔的微笑 說起多數據源,一般都來解決那些問題呢,主從模式或者業務比較復雜需要連接不同的分庫來支持業務。我們項目是後者的模式,網上找了很多,大都是根據jpa來做多數據源解決方案,要

maven搭建springboot+mybatis+freemarker

username etag actor dmi mysql result resource tro pac 創建maven項目後,在pox.xml中添加依賴的jar包 <project xmlns="http://maven.apache.org/POM/4.0.

使用idea+springboot+Mybatis搭建web項目

data rom project mysql ride 接口 mar isp 結構 使用idea+springboot+Mybatis搭建web項目 springboot的優勢之一就是快速搭建項目,省去了自己導入jar包和配置xml的時間,使用非常方便。 1、創建項目p

idea+springboot+Mybatis搭建web項目

.com pin cache 完成後 stat idea leaf als div 使用idea+springboot+Mybatis搭建一個簡單的web項目。 首先新建一個項目; 在這裏選擇Maven項目也可以,但是IDEA為我們提供了一種更方便快捷的創建方法,即Spr

springboot+mybatis+SpringSecurity 實現用戶角色數據庫管理

.html ngs list css per title 。。 nfa from 本文使用springboot+mybatis+SpringSecurity 實現用戶權限數據庫管理 實現用戶和角色用數據庫存儲,而資源(url)和權限的對應采用硬編碼配置。 也就是角色可以訪問

SpringBoot ( 七 ) :springboot + mybatis 多數據源最簡解決方案

lock factory interface name manager 兩個 ppi ati ctype 說起多數據源,一般都來解決那些問題呢,主從模式或者業務比較復雜需要連接不同的分庫來支持業務。我們項目是後者的模式,網上找了很多,大都是根據jpa來做多數據源解決方案,要

springboot-mybatis 批量insert

att ssr time 映射 兼容 tlist return isp element springboot mybatis 批量insert 操作 直接上代碼: 1.首先要在pom.xml中導入包: springboot 1.5.8 <dependency>

springboot + mybatis配置分頁插件

XML control framework cti sarg location @override html apache 1:首先配置springboot +mybatis框架 參考:http://www.cnblogs.com/liyafei/p/791154

springboot mybatis 事務管理

private 測試 love cto frame update 數據源 ren jdbc 本文主要講述springboot提供的聲明式的事務管理機制。 一、一些概念 聲明式的事務管理是基於AOP的,在springboot中可以通過@Transactional註解的方式

springboot + mybatis +druid

ima eth hid time col sele ons getname uid Druid Spring Boot Starter mybatis-spring-boot-autoconfigure 新建spring boot工程,添加pom依賴 <depen

企業分布式微服務雲SpringCloud SpringBoot mybatis (七)Spring Boot中使用JdbcTemplate訪問數據庫

ger sele 應該 創建 測試環境 oid reg tis eat 本文介紹在Spring Boot基礎下配置數據源和通過JdbcTemplate編寫數據訪問的示例。 數據源配置 在我們訪問數據庫的時候,需要先配置一個數據源,下面分別介紹一下幾種不同的數據庫配置方式。