@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]) @Inherited class Sql
@Sql is used to annotate a test class or test method to configure SQL #scripts and #statements to be executed against a given database during integration tests.
Method-level declarations override class-level declarations.
Script execution is performed by the SqlScriptsTestExecutionListener, which is enabled by default.
The configuration options provided by this annotation and SqlConfig are equivalent to those supported by org.springframework.jdbc.datasource.init.ScriptUtils and org.springframework.jdbc.datasource.init.ResourceDatabasePopulator but are a superset of those provided by the <jdbc:initialize-database/> XML namespace element. Consult the javadocs of individual attributes in this annotation and SqlConfig for details.
Beginning with Java 8, @Sql can be used as a Repeatable annotation. Otherwise, SqlGroup can be used as an explicit container for declaring multiple instances of @Sql.
This annotation may be used as a meta-annotation to create custom composed annotations with attribute overrides.
Author
Sam Brannen
Since
4.1
See Also
SqlConfigSqlGroupSqlScriptsTestExecutionListenerorg.springframework.transaction.annotation.Transactionalorg.springframework.test.context.transaction.TransactionalTestExecutionListenerorg.springframework.jdbc.datasource.init.ResourceDatabasePopulatororg.springframework.jdbc.datasource.init.ScriptUtils
Sql(vararg value: String, scripts: Array<String>, statements: Array<String>, executionPhase: ExecutionPhase, config: SqlConfig)
Method-level declarations override class-level declarations. Script execution is performed by the SqlScriptsTestExecutionListener, which is enabled by default. The configuration options provided by this annotation and SqlConfig are equivalent to those supported by org.springframework.jdbc.datasource.init.ScriptUtils and org.springframework.jdbc.datasource.init.ResourceDatabasePopulator but are a superset of those provided by the Beginning with Java 8, This annotation may be used as a meta-annotation to create custom composed annotations with attribute overrides. |
val config: SqlConfig
Local configuration for the SQL scripts and statements declared within this See the class-level javadocs for SqlConfig for explanations of local vs. global configuration, inheritance, overrides, etc. Defaults to an empty SqlConfig instance. |
|
val executionPhase: ExecutionPhase
When the SQL scripts and statements should be executed. Defaults to |
|
val scripts: Array<String>
The paths to the SQL scripts to execute. This attribute may not be used in conjunction with Each path will be interpreted as a Spring org.springframework.core.io.Resource. A plain path — for example, If no SQL scripts or
|
|
val statements: Array<String>
Inlined SQL statements to execute. This attribute may be used in conjunction with or instead of Statements declared via this attribute will be executed after statements loaded from resource |
|
val value: Array<String>
Alias for This attribute may not be used in conjunction with |