Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging @Sql from superclass with @Sql in subclass

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?

like image 385
Rahul Sharma Avatar asked Feb 07 '23 05:02

Rahul Sharma


1 Answers

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)

like image 110
Sam Brannen Avatar answered Feb 11 '23 18:02

Sam Brannen