MapperRegistry 不知道映射器文件

Mapper file is not known to the MapperRegistry

我试图在 Spring 启动时用 mybatis 显示 mysql 数据库中的所有数据。但是,MapperRegistry 不知道 mapper.xml 文件。

我试过更改 application.yaml 的类路径。

application.yaml

mybatis:
  mapper-locations: classpath:com/example/demo/repository/mybatis/*.xml

购物Class

public class Shop {
    private String shopId;

    private String shopName;

    public Shop() {
        }

    public Shop(String shopId, String shopName) {
        this.shopId = shopId;
        this.shopName = shopName;
    }
}

ShopMapper.xml

    <!-- Mapping Shop Class to Shop tables -->
    <resultMap id="Shop"
               type="com.example.demo.domain.Shop">
        <id property="shopId" column="SHOP_ID"/>
        <result property="shopName" column="SHOP_NAME"/>
    </resultMap>


    <!-- Show all shops with the designated shopid -->
    <select id="get" resultMap="Shop">
        SELECT SHOP_ID, SHOP_NAME FROM SHOP
        WHERE SHOP_ID = #{shopId}
    </select>

</mapper>

商店资源库

public Shop findOne(String shopId) {
    Shop shop = this.sqlSessionTemplate.getMapper(ShopMapper.class).get(shopId);
   return shop;
}

控制器

@RestController
    public class PageController {
    @GetMapping(path = "/{shopId}", produces = "application/json")
    public Shop get(@PathVariable String shopId) {
        return this.service.get(shopId);
    }
}

错误: org.apache.ibatis.binding.BindingException:MapperRegistry

不知道类型接口 com.example.demo.repository.mybatis.ShopMapper

您需要添加一个接口来匹配 ShopMapper.xml

@Mapper
public interface ShopMapper {
    Shop get(Long shopId);
}