If you need to set some field you can use @AliasFor. Example.
Instead of using this verbose annotations:
@Test
@Sql(
config = SqlConfig(
dataSource = "myDataSource",
transactionManager = "myTransactionManager",
),
scripts = ["/myScript.sql"],
)
test()
I can create my own annotation that will container those that I want to customize. Note that I had to use the @aliasFor annotation to keep my ability to customize some fields:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlConfig;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Sql(config = @SqlConfig(
dataSource = "mnDataSource",
transactionManager = "myTransactionManager"
))
public @interface SqlMyDB {
@AliasFor(annotation = Sql.class, attribute = "scripts")
String[] scripts() default {};
}
Now I can simply do:
@Test
@SqlMyDB(scripts = ["/myScript.sql"])
test()
Note that @AliasFor is a Spring annotation and will only work if:
- You use it for Spring Framework Annotations
- Use Spring Annotation utils like with Eric's answer
- Code the equivalent logic yourself.
@With(Secure.class)
, OP now has to write@Secure(superAnnotation = @With(Secure.class))
? How does that help? – Tumult