简体   繁体   中英

MyBatis Spring-Boot Multi-Module configuration BindingException

I'm trying to reach my very simple endpoint (http://localhost:8100/user/1) on my (future) micro-services app with spring-boot and mybatis as mapper but I'm getting this error.

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): fr.mydomain.user.service.UserReadService.findById

Saw a lot of people getting this error, I tried every "fix" I saw but nothing is working...

architecture

UserMapper.java

package fr.mydomain.user.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import fr.mydomain.user.model.User;

@Mapper
public interface UserMapper {
    User findById(@Param("id") Long id);
}

UserMapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="fr.mydomain.user.mapper.UserMapper">
    <resultMap type="fr.mydomain.user.model.User" id="usermap">
        <id column="id" property="id"/>
    </resultMap>
    <select id="findById" resultMap="usermap">
        SELECT id FROM user
        WHERE id = #{id};
    </select>
</mapper>

SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>
   <mappers>
      <mapper resource="fr/mydomain/user/mapper/UserMapper.xml"/>
   </mappers>
</configuration>

Is someone can see what am I missing?

Edit: you can find the project on my github here just need to configure your db

Found my problem, it was in my CoreApplication.java

@SpringBootApplication(scanBasePackages = "fr.mydomain.user")
@MapperScan("fr.mydomain.user")
public class CoreApplication {

    public static void main(String[] args) {
        SpringApplication.run(CoreApplication.class, args);
    }

}

I thought the MapperScan annotation was looking for Mapper annotation but it's actually considering every class as mapper, so it was considering my service as a mapper...

@MapperScan("fr.mydomain.user") => @MapperScan("fr.mydomain.user.mapper")

can you post you project to github and share project? I alse build maven multi-module sringboot+mybatis and can not running thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM