Skip to content

测试框架中的数据源和 SQL 执行顺序存在问题 #204

@CodeCasterX

Description

@CodeCasterX

问题摘要 / Issue Summary

当一个 Bean 中构造函数中使用数据访问 Mapper 时,无法生效

版本信息 / Version Information

v3.5.0-M4

浏览器 / Browser

No response

操作系统 / Operating System

None

发生了什么?/ What happened?

正常测试代码初始化是没有问题的,但是一旦在某个 Bean 的构造函数中使用 Mapper 进行数据访问时,集成测试就会报错。

报错内容是缺少数据源的 Bean。

期望的行为 / Expected Behavior

期望不管在 Bean 的构造函数还是其他地方,访问数据,不管是正常启动还是测试运行,都能够正常访问数据,没有报错。

重现步骤 / Steps to Reproduce

  1. 在任意一个带数据访问的 Bean 的构造函数中增加一行数据访问代码。
  2. 运行带有集成测试注解的测试用例。

相关日志 / Relevant Logs

以下日志为将数据访问尝试提前放进去后的新增错误日志,也就是说,调整数据源的初始化时间点是可行的,但是后续还有其他需要调整的点:

Caused by: modelengine.fitframework.transaction.DataAccessException: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "store_tool" not found; SQL statement:
select i."name", i."group_name", i."definition_name", i."definition_group_name", i."unique_name", i."schema", i."runnables", i."extensions", i."version", i."is_latest"
        from "store_tool" i
     
        where unique_name = ?
        and is_latest = true [42102-224]
### The error may exist in ToolMapper.xml
### The error may involve modelengine.jade.carver.tool.repository.pgsql.mapper.ToolMapper.getToolByUniqueName
### The error occurred while executing a query
### SQL: select i."name", i."group_name", i."definition_name", i."definition_group_name", i."unique_name", i."schema", i."runnables", i."extensions", i."version", i."is_latest"         from "store_tool" i               where unique_name = ?         and is_latest = true
### Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "store_tool" not found; SQL statement:

额外信息 / Additional Context

No response

确认事项 / Confirmations

  • 我已经搜索了现有的issues,确认这不是重复问题
    I have searched existing issues and confirmed this is not a duplicate

  • 我已经阅读了项目文档和 FAQ
    I have read the project documentation and FAQ

  • 我提供的信息准确完整
    The information I provided is accurate and complete

  • 我愿意协助测试问题修复 (可选)
    I'm willing to help test the bug fix (optional)

Metadata

Metadata

Assignees

Labels

in: fitIssues in FIT modulestype: bugA general bug

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions