Merging @Sql from superclass with @Sql in subclass

安稳与你 提交于 2019-12-23 12:17:53

问题


I have an abstract class annotated with @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts="someScript") .

I have a test class which inherits from the abstract class. The child class is also annotated with @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts="someOtherScript").

When I was running spring boot 1.2, everything worked as I expected it to: scripts from parent class were run before child class. I upgraded to spring boot 1.3 and now, the child class's @Sql overrides parent class's @Sql and the parent class scripts are never run.

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


回答1:


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

OK, after some investigative work, I have come up with an answer to your question.

Short Answer

No, what you are attempting to do is unfortunately not possible.

Detailed Answer

By design, merging of a local class-level declaration of @Sql with a class-level declaration of @Sql on a superclass has never been supported. A local declaration was always intended to override a declaration on a superclass.

Thus, you were simply lucky (or unlucky, depending on how you see it) that it worked for you at all.

The only reason it ever worked for you was due to a bug in core Spring's support for looking up @Repeatable annotations (see SPR-13068 for details).

However, this bug was fixed in Spring Framework 4.2, and since Spring Boot 1.3 automatically upgraded your Spring Framework dependencies to 4.2 that's why you noticed the issue after the Spring Boot upgrade.

Regards,

Sam (author of the Spring TestContext Framework)




回答2:


After @SamBrannen's answer, I ended up running the script from child class using ScriptUtils.execute method.



来源:https://stackoverflow.com/questions/39296329/merging-sql-from-superclass-with-sql-in-subclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!