将超类中的@Sql与子类中的@Sql合并

Merging @Sql from superclass with @Sql in subclass

我有一个摘要 class 用 @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts="someScript") 注释。

我有一个测试 class 继承自摘要 class。 child class 也被注释为 @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts="someOtherScript").

当我 运行 宁 spring 启动 1.2 时,一切都按我预期的那样工作:来自 parent class 的脚本在 运行 之前 child class。我升级到 spring 引导 1.3,现在 child class 的 @Sql 覆盖 parent class 的 @Sql 和parent class 脚本永远不会 运行.

使用 spring boot 1.3 有不同的方法吗?所以 parent class 脚本是 运行 在 child class 脚本之前?

With spring boot 1.3 is there a different way of doing this? So that parent class scripts are run before child class scripts?

好的,经过一些调查工作,我得出了您问题的答案。

简答

不,很遗憾,您尝试做的事情是不可能的。

详细解答

通过设计,将 @Sql 的本地 class 级声明与超级 class 上的 class 级 @Sql 声明合并从未得到支持。本地声明总是旨在覆盖 superclass.

上的声明

因此,你只是幸运(或不幸,取决于你如何看待它)它对你有用。

它对您有用的唯一原因是核心 Spring 对查找 @Repeatable 注释的支持中存在错误(有关详细信息,请参阅 SPR-13068)。

但是,此错误已在 Spring Framework 4.2 中修复,并且由于 Spring Boot 1.3 自动将您的 Spring Framework 依赖项升级到 4.2,这就是为什么您在 Spring开机升级.

此致,

Sam(Spring TestContext Framework 的作者)

在@SamBrannen 的 之后,我使用 ScriptUtils.execute 方法结束了 运行 来自 child class 的脚本。