Skip to content

Commit

Permalink
MybatisPlus多数据源错误-记录
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed May 10, 2024
1 parent ad7611e commit a04915d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/chapter/note.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,21 @@ linux /root/.config/Ultralytics/
springdoc:
api-docs:
path: v3/api-docs # 此为相对路径 若前缀有/ 则为绝对路径
```
## MyBatis-Plus多数据源使用xml时出现`Invalid bound statement (not found)`

**原因:** 在使用自定义的`@Configuration`注解配置`MybatisSqlSessionFactoryBean`时,`application.yaml`中的配置不起作用,需要指定`MapperLocations`
**解决办法:**
```java{7}
@Bean("sqlSessionFactory")
@Primary
public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:/mapper/remote/**/*.xml"));
return sqlSessionFactoryBean.getObject();
}
```

0 comments on commit a04915d

Please sign in to comment.