File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
spring-boot-project/spring-boot-autoconfigure/src
main/java/org/springframework/boot/autoconfigure/batch
test/java/org/springframework/boot/autoconfigure/batch Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 6666 * @author Mahmoud Ben Hassine
6767 * @author Lars Uffmann
6868 * @author Lasse Wulff
69+ * @author Yanming Zhou
6970 * @since 1.0.0
7071 */
7172@ AutoConfiguration (after = { HibernateJpaAutoConfiguration .class , TransactionAutoConfiguration .class })
@@ -140,6 +141,12 @@ protected String getTablePrefix() {
140141 return (tablePrefix != null ) ? tablePrefix : super .getTablePrefix ();
141142 }
142143
144+ @ Override
145+ protected boolean getValidateTransactionState () {
146+ Boolean validateTransactionState = this .properties .getJdbc ().getValidateTransactionState ();
147+ return (validateTransactionState != null ) ? validateTransactionState : super .getValidateTransactionState ();
148+ }
149+
143150 @ Override
144151 protected Isolation getIsolationLevelForCreate () {
145152 Isolation isolation = this .properties .getJdbc ().getIsolationLevelForCreate ();
Original file line number Diff line number Diff line change 2727 * @author Eddú Meléndez
2828 * @author Vedran Pavic
2929 * @author Mukul Kumar Chaundhyan
30+ * @author Yanming Zhou
3031 * @since 1.2.0
3132 */
3233@ ConfigurationProperties ("spring.batch" )
@@ -67,6 +68,11 @@ public static class Jdbc {
6768 private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/"
6869 + "batch/core/schema-@@platform@@.sql" ;
6970
71+ /**
72+ * Whether to validate the transaction state.
73+ */
74+ private Boolean validateTransactionState ;
75+
7076 /**
7177 * Transaction isolation level to use when creating job meta-data for new jobs.
7278 */
@@ -93,6 +99,14 @@ public static class Jdbc {
9399 */
94100 private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode .EMBEDDED ;
95101
102+ public Boolean getValidateTransactionState () {
103+ return this .validateTransactionState ;
104+ }
105+
106+ public void setValidateTransactionState (Boolean validateTransactionState ) {
107+ this .validateTransactionState = validateTransactionState ;
108+ }
109+
96110 public Isolation getIsolationLevelForCreate () {
97111 return this .isolationLevelForCreate ;
98112 }
Original file line number Diff line number Diff line change 9090import org .springframework .jdbc .datasource .init .DatabasePopulator ;
9191import org .springframework .orm .jpa .JpaTransactionManager ;
9292import org .springframework .transaction .PlatformTransactionManager ;
93+ import org .springframework .transaction .annotation .Isolation ;
9394
9495import static org .assertj .core .api .Assertions .assertThat ;
9596import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
107108 * @author Mahmoud Ben Hassine
108109 * @author Lars Uffmann
109110 * @author Lasse Wulff
111+ * @author Yanming Zhou
110112 */
111113@ ExtendWith (OutputCaptureExtension .class )
112114class BatchAutoConfigurationTests {
@@ -520,6 +522,18 @@ void defaultExecutionContextSerializerIsUsed() {
520522 });
521523 }
522524
525+ @ Test
526+ void customJdbcPropertiesIsUsed () {
527+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
528+ .withPropertyValues ("spring.batch.jdbc.validate-transaction-state:false" ,
529+ "spring.batch.jdbc.isolation-level-for-create:READ_COMMITTED" )
530+ .run ((context ) -> {
531+ SpringBootBatchConfiguration configuration = context .getBean (SpringBootBatchConfiguration .class );
532+ assertThat (configuration .getValidateTransactionState ()).isEqualTo (false );
533+ assertThat (configuration .getIsolationLevelForCreate ()).isEqualTo (Isolation .READ_COMMITTED );
534+ });
535+ }
536+
523537 private JobLauncherApplicationRunner createInstance (String ... registeredJobNames ) {
524538 JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner (mock (JobLauncher .class ),
525539 mock (JobExplorer .class ), mock (JobRepository .class ));
You can’t perform that action at this time.
0 commit comments