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...
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")