mybatis-spring-boot-starter 1.0.1 之后的版本问题

来源:互联网 发布:初学钢琴软件 编辑:程序博客网 时间:2024/05/02 04:58

mapper接口

@MapperScanpublic interface PeopleMapper {    @Select("SELECT * FROM people WHERE id = #{id}")    People findById(@Param("id") int id);    @Insert("INSERT INTO people(NAME, AGE) VALUES(#{name}, #{age})")    int insert(People people);}

pom

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

此时mapper是可以正常使用的
但是将mybatis-spring-boot-starter的版本改为1.1.1或者1.3.0之后,则会报错

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘demo.repository.Dao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

错误信息详见spring boot mybatis的问题(提的问题没人回答。。后来自己回答了,然后在记录一下)

然后某一天脑袋一抽,想到会不会是注解问题,然后更换注解为@Mapper
mapper接口

@Mapperpublic interface PeopleMapper {    @Select("SELECT * FROM people WHERE id = #{id}")    People findById(@Param("id") int id);    @Insert("INSERT INTO people(NAME, AGE) VALUES(#{name}, #{age})")    int insert(People people);}

pom

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

发现更换注解后就可照常使用,同测版本1.1.1可用

原创粉丝点击