Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[功能改进]: Db kit增加对多数据源的支持 #6577

Open
3 tasks done
archfish opened this issue Nov 7, 2024 · 2 comments
Open
3 tasks done

[功能改进]: Db kit增加对多数据源的支持 #6577

archfish opened this issue Nov 7, 2024 · 2 comments
Assignees

Comments

@archfish
Copy link

archfish commented Nov 7, 2024

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

功能改进

单独使用Db kit可以正常完成功能,增加https://github.com/baomidou/dynamic-datasource 后发现无法切换数据源。希望增加对多数据源的支持

参考资料

JDK Version: temurin64-21.0.3

SpringBoot Version: 3.3.5

mybatis-plus:3.5.9

dynamic-datasource-spring-boot-starter Version:4.3.1

druid Version: 无

Mapper上使用@DS注解,多数据源切换在db kit中无法正常切换。

db kit中使用的mapper是未经dynamic-datasource代理的mapper所以注解未生效。改为service中使用baseMapper则正常。

Steps to reproduce

// entity/Task.java
@Data
public class Task {
    @TableId(type = IdType.AUTO)
    protected Integer id;
}
// mapper/TaskMapper.java
@DS("old")
public interface TaskMapper extends BaseMapper<Task> {
}
// Main.java
@MapperScan({"com.cc.mapper"})
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}
Task task = Db.getById(id, Task.class);

初步定位问题代码:

public final class SqlHelper {
    public static <T, R, M extends BaseMapper<T>> R execute(Class<T> entityClass, SFunction<M, R> sFunction) {
        SqlSession sqlSession = sqlSession(entityClass);
        try {
            return sFunction.apply(getMapper(entityClass, sqlSession));
        } finally {
            CompatibleHelper.getCompatibleSet().closeSqlSession(sqlSession, GlobalConfigUtils.currentSessionFactory(entityClass));
        }
    }
}

getMapper(entityClass, sqlSession) 这里获取的不是最终代理的mapper

@archfish
Copy link
Author

archfish commented Nov 7, 2024

@VampireAchao VampireAchao self-assigned this Nov 7, 2024
@VampireAchao
Copy link
Contributor

在做了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants