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
3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 66
66
* @author Mahmoud Ben Hassine
67
67
* @author Lars Uffmann
68
68
* @author Lasse Wulff
69
+ * @author Yanming Zhou
69
70
* @since 1.0.0
70
71
*/
71
72
@ AutoConfiguration (after = { HibernateJpaAutoConfiguration .class , TransactionAutoConfiguration .class })
@@ -140,6 +141,12 @@ protected String getTablePrefix() {
140
141
return (tablePrefix != null ) ? tablePrefix : super .getTablePrefix ();
141
142
}
142
143
144
+ @ Override
145
+ protected boolean getValidateTransactionState () {
146
+ Boolean validateTransactionState = this .properties .getJdbc ().getValidateTransactionState ();
147
+ return (validateTransactionState != null ) ? validateTransactionState : super .getValidateTransactionState ();
148
+ }
149
+
143
150
@ Override
144
151
protected Isolation getIsolationLevelForCreate () {
145
152
Isolation isolation = this .properties .getJdbc ().getIsolationLevelForCreate ();
Original file line number Diff line number Diff line change 27
27
* @author Eddú Meléndez
28
28
* @author Vedran Pavic
29
29
* @author Mukul Kumar Chaundhyan
30
+ * @author Yanming Zhou
30
31
* @since 1.2.0
31
32
*/
32
33
@ ConfigurationProperties ("spring.batch" )
@@ -67,6 +68,11 @@ public static class Jdbc {
67
68
private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/"
68
69
+ "batch/core/schema-@@platform@@.sql" ;
69
70
71
+ /**
72
+ * Whether to validate the transaction state.
73
+ */
74
+ private Boolean validateTransactionState ;
75
+
70
76
/**
71
77
* Transaction isolation level to use when creating job meta-data for new jobs.
72
78
*/
@@ -93,6 +99,14 @@ public static class Jdbc {
93
99
*/
94
100
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode .EMBEDDED ;
95
101
102
+ public Boolean getValidateTransactionState () {
103
+ return this .validateTransactionState ;
104
+ }
105
+
106
+ public void setValidateTransactionState (Boolean validateTransactionState ) {
107
+ this .validateTransactionState = validateTransactionState ;
108
+ }
109
+
96
110
public Isolation getIsolationLevelForCreate () {
97
111
return this .isolationLevelForCreate ;
98
112
}
Original file line number Diff line number Diff line change 90
90
import org .springframework .jdbc .datasource .init .DatabasePopulator ;
91
91
import org .springframework .orm .jpa .JpaTransactionManager ;
92
92
import org .springframework .transaction .PlatformTransactionManager ;
93
+ import org .springframework .transaction .annotation .Isolation ;
93
94
94
95
import static org .assertj .core .api .Assertions .assertThat ;
95
96
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
107
108
* @author Mahmoud Ben Hassine
108
109
* @author Lars Uffmann
109
110
* @author Lasse Wulff
111
+ * @author Yanming Zhou
110
112
*/
111
113
@ ExtendWith (OutputCaptureExtension .class )
112
114
class BatchAutoConfigurationTests {
@@ -520,6 +522,18 @@ void defaultExecutionContextSerializerIsUsed() {
520
522
});
521
523
}
522
524
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
+
523
537
private JobLauncherApplicationRunner createInstance (String ... registeredJobNames ) {
524
538
JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner (mock (JobLauncher .class ),
525
539
mock (JobExplorer .class ), mock (JobRepository .class ));
You can’t perform that action at this time.
0 commit comments