天天看點

mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found

具及背景: IntelliJ IDEA 2016.1.3 Ultimate。spring boot, maven項目,利用mybatis 注解的方式查詢mysql。

業務邏輯關系:controller --> Service接口 ----> serverImpl --->Dao -->DaoImpl ---> mapper -->db

問題:mapper提示Could not autowire. No beans of … type found?如圖:

mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found

其中ProductDaoMyBatisMapper是個接口,用于查詢mysql,結構如下圖:

mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found

解決辦法:将第一張圖中的ProductDaoMyBatis類序列化,即實作Serializable 接口即可,如下圖:

mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found

補:pom.xml

<!--mybatis-->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
</dependency>

方法二: 還有一種方式,修改idea配置,将spring 的severity的值設定為"warning", 如下:      
mybatis+spring boot, mapper 提示Could not autowire. No beans of … type found