Spring Boot 项目中 Mybatis 访问 Oracle 多数据库:解决 XML 扫描问题
可能是因为没有正确配置 Mybatis 的 mapper 扫描路径。需要在 application.yml(或 application.properties)中添加以下配置:
mybatis:
mapper-locations: classpath*:mapper/*.xml
其中,'mapper/.xml' 是你的 mapper xml 文件所在的相对路径。如果你的 mapper xml 文件在 com.example.mapper 包下,则应该配置为 'classpath:com/example/mapper/*.xml'。
另外,如果你的 mapper 接口和 xml 文件没有放在同一个包下,还需要在 mapper 接口上添加 @Mapper 注解,或者在启动类上添加 @MapperScan 注解,来让 Mybatis 扫描到这些 mapper 接口。
@Mapper
public interface UserMapper {
//...
}
或者
@SpringBootApplication
@MapperScan("com.example.mapper")
public class DemoApplication {
//...
}
原文地址: https://www.cveoy.top/t/topic/ovrY 著作权归作者所有。请勿转载和采集!