注释类型 SqlConfig
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface SqlConfig
@SqlConfigdefines metadata that is used to determine how to parse and execute SQL scripts configured via the@Sqlannotation.Configuration Scope
When declared as a class-level annotation on an integration test class,
@SqlConfigserves as global configuration for all SQL scripts within the test class hierarchy. When declared directly via theconfigattribute of the@Sqlannotation,@SqlConfigserves as local configuration for the SQL scripts declared within the enclosing@Sqlannotation.Default Values
Every attribute in
@SqlConfighas an implicit default value which is documented in the javadocs of the corresponding attribute. Due to the rules defined for annotation attributes in the Java Language Specification, it is unfortunately not possible to assign a value ofnullto an annotation attribute. Thus, in order to support overrides of inherited global configuration,@SqlConfigattributes have an explicitdefaultvalue of either""for Strings,{}for arrays, orDEFAULTfor Enums. This approach allows local declarations of@SqlConfigto selectively override individual attributes from global declarations of@SqlConfigby providing a value other than"",{}, orDEFAULT.Inheritance and Overrides
Global
@SqlConfigattributes are inherited whenever local@SqlConfigattributes do not supply an explicit value other than"",{}, orDEFAULT. Explicit local configuration therefore overrides global configuration.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen, Tadaya Tsuyukubo
- 另请参阅:
Sql
可选元素概要
可选元素 修饰符和类型 可选元素 说明 StringblockCommentEndDelimiterThe end delimiter that identifies block comments within the SQL scripts.StringblockCommentStartDelimiterThe start delimiter that identifies block comments within the SQL scripts.StringcommentPrefixThe prefix that identifies single-line comments within the SQL scripts.String[]commentPrefixesThe prefixes that identify single-line comments within the SQL scripts.StringdataSourceThe bean name of theDataSourceagainst which the scripts should be executed.StringencodingThe encoding for the supplied SQL scripts, if different from the platform encoding.SqlConfig.ErrorModeerrorModeThe mode to use when an error is encountered while executing an SQL statement.StringseparatorThe character string used to separate individual statements within the SQL scripts.StringtransactionManagerThe bean name of thePlatformTransactionManagerthat should be used to drive transactions.SqlConfig.TransactionModetransactionModeThe mode to use when determining whether SQL scripts should be executed within a transaction.
元素详细资料
dataSource
String dataSource
The bean name of theDataSourceagainst which the scripts should be executed.The name is only required if there is more than one bean of type
DataSourcein the test'sApplicationContext. If there is only one such bean, it is not necessary to specify a bean name.Defaults to an empty string, requiring that one of the following is true:
- An explicit bean name is defined in a global declaration of
@SqlConfig. - The data source can be retrieved from the transaction manager by using reflection to invoke a public method named
getDataSource()on the transaction manager. - There is only one bean of type
DataSourcein the test'sApplicationContext. - The
DataSourceto use is named"dataSource".
- 默认值:
- ""
- An explicit bean name is defined in a global declaration of
transactionManager
String transactionManager
The bean name of thePlatformTransactionManagerthat should be used to drive transactions.The name is only used if there is more than one bean of type
PlatformTransactionManagerin the test'sApplicationContext. If there is only one such bean, it is not necessary to specify a bean name.Defaults to an empty string, requiring that one of the following is true:
- An explicit bean name is defined in a global declaration of
@SqlConfig. - There is only one bean of type
PlatformTransactionManagerin the test'sApplicationContext. TransactionManagementConfigurerhas been implemented to specify whichPlatformTransactionManagerbean should be used for annotation-driven transaction management.- The
PlatformTransactionManagerto use is named"transactionManager".
- 默认值:
- ""
- An explicit bean name is defined in a global declaration of
transactionMode
SqlConfig.TransactionMode transactionMode
The mode to use when determining whether SQL scripts should be executed within a transaction.Defaults to
DEFAULT.Can be set to
SqlConfig.TransactionMode.ISOLATEDto ensure that the SQL scripts are executed in a new, isolated transaction that will be immediately committed.- 默认值:
- org.springframework.test.context.jdbc.SqlConfig.TransactionMode.DEFAULT
separator
String separator
The character string used to separate individual statements within the SQL scripts.Implicitly defaults to
";"if not specified and falls back to"\n"as a last resort.May be set to
ScriptUtils.EOF_STATEMENT_SEPARATORto signal that each script contains a single statement without a separator.- 默认值:
- ""
commentPrefix
String commentPrefix
The prefix that identifies single-line comments within the SQL scripts.Implicitly defaults to
"--".This attribute may not be used in conjunction with
commentPrefixes, but it may be used instead ofcommentPrefixes.- 默认值:
- ""
commentPrefixes
String[] commentPrefixes
The prefixes that identify single-line comments within the SQL scripts.Implicitly defaults to
["--"].This attribute may not be used in conjunction with
commentPrefix, but it may be used instead ofcommentPrefix.- 从以下版本开始:
- 5.2
- 另请参阅:
ScriptUtils.DEFAULT_COMMENT_PREFIXES,commentPrefix()
- 默认值:
- {}
blockCommentStartDelimiter
String blockCommentStartDelimiter
The start delimiter that identifies block comments within the SQL scripts.Implicitly defaults to
"/*".- 默认值:
- ""
blockCommentEndDelimiter
String blockCommentEndDelimiter
The end delimiter that identifies block comments within the SQL scripts.Implicitly defaults to
"*/".- 默认值:
- ""
errorMode
SqlConfig.ErrorMode errorMode
The mode to use when an error is encountered while executing an SQL statement.Defaults to
DEFAULT.- 另请参阅:
SqlConfig.ErrorMode
- 默认值:
- org.springframework.test.context.jdbc.SqlConfig.ErrorMode.DEFAULT