springboot整合mybatis时一直加载不到xml中的方法

报错信息如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.user.dao.UserDao.XXX(方法名)

下面是我application.yml的配置:

server:
  port: 8080
spring:
  mybatis:
    mapper-locations: classpath:mapper/*.xml
  datasource:
    url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver

启动类配置:

@SpringBootApplication
@MapperScan("com.example.user.dao")
public class Demo4Application {
    public static void main(String[] args) {
        SpringApplication.run(Demo4Application.class, args);
    }
}

项目结构:

UserDao.xml文件在resources的mapper下,UserDao接口在com.example.user.dao下

有没有大神帮忙看看哪里出的问题。直接在UserDao使用注解是可以访问到的,如下

 @Select("SELECT * FROM user_t where id= #{id}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "user_name",property = "userName"),
            @Result(column = "password",property = "password"),
            @Result(column = "age",property = "age")
    })
    User selectByPrimaryKey(Integer id);

但就是访问不到xml文件中的方法,我使用的Idea2018,有没有大神指导指导,谢谢啦

可以能是你的用法还是不太对,参考这篇再完整找找问题:
https://www.cnblogs.com/zhuxiaojie/p/5836159.html

问题解决了,在配置文件中我将mybatis放到spring配置的下面导致出错。mybatis配置应当是与spring配置同级别的。一个制位符的差别

如果你要通过xml来整合mybatis的方式,你需要在配置文件中声明mybatis.config-location和mybatis.mapper-locations,这样你就不需要注解@MapperScan去扫描,不通过xml的方式就是你上面这种,不需要xml文件直接通过注解的sql就行了