【踩坑小記】springBoot應用啓動報錯,變量未找到依賴的實體類

今天,在運行springboot項目遇到了報錯,經過研究後終於發現了坑在哪裏,記錄以下,避免再次踩坑。

***************************

APPLICATION FAILED TO START

***************************

Description:

Field roleMapper in com.onezero.springboottest.service.impl.RoleServiceImpl required a bean of type 'com.onezero.springboottest.mapper.RoleMapper' that could not be found.

The injection point has the following annotations:

- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type 'com.onezero.springboottest.mapper.RoleMapper' in your configuration.

雖然說註解都沒有遺漏,都添加到指定的地方,但是在運行應用時仍然報錯,報錯信息如下:

Field roleMapper in com.onezero.springboottest.service.impl.RoleServiceImpl required a bean of type 'com.onezero.springboottest.mapper.RoleMapper' that could not be found.

The injection point has the following annotations:

- @org.springframework.beans.factory.annotation.Autowired(required=true)

翻譯過來就是:

com.onezero.springboottest.service.impl.RoleServiceImpl中的變量roleMapper沒有找到依賴的一個com.onezero.springboottest.mapper.RoleMapper類型的實體類。

研究之後發現,問題出在引入的依賴上,注意引入的依賴是mybatis-spring-boot-starter而不是mybatis,所以需要將pom.xml文件中引入的依賴做下修改,引入新的mybatis-spring-boot-starter依賴.

 

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

修改之後在試着去重啓應用,發現啓動成功了!

順利從坑裏出來!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章