Skip to content

Commit 85a8682

Browse files
committed
Added possibility to use a custom JobParametersConverter within JobOperationsController
1 parent 894a3db commit 85a8682

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

batch-web-spring-boot-autoconfigure/src/main/java/de/codecentric/batch/configuration/BatchWebAutoConfiguration.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package de.codecentric.batch.configuration;
1818

1919
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
20+
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
21+
import org.springframework.batch.core.converter.JobParametersConverter;
2022
import org.springframework.batch.core.job.AbstractJob;
2123
import org.springframework.batch.core.launch.NoSuchJobException;
2224
import org.springframework.beans.factory.annotation.Autowired;
2325
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
2426
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2528
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2629
import org.springframework.context.ApplicationListener;
2730
import org.springframework.context.annotation.Bean;
@@ -127,4 +130,10 @@ public int getOrder() {
127130
return Ordered.LOWEST_PRECEDENCE;
128131
}
129132

133+
@Bean
134+
@ConditionalOnMissingBean
135+
public JobParametersConverter jobParametersConverter() {
136+
return new DefaultJobParametersConverter();
137+
}
138+
130139
}

batch-web-spring-boot-autoconfigure/src/main/java/de/codecentric/batch/web/JobOperationsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public class JobOperationsController {
154154

155155
private JsrJobOperator jsrJobOperator;
156156

157-
private JobParametersConverter jobParametersConverter = new DefaultJobParametersConverter();
157+
@Autowired
158+
private JobParametersConverter jobParametersConverter;
158159

159160
private JobLogFileNameCreator jobLogFileNameCreator = new DefaultJobLogFileNameCreator();
160161

batch-web-spring-boot-samples/batch-boot-simple/src/main/java/de/codecentric/batch/simple/Application.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ public static void main(String[] args) {
1919
// public BatchConfigurer batchConfigurer(DataSource dataSource){
2020
// return new DefaultBatchConfigurer(dataSource);
2121
// }
22+
23+
// If you would like to use your own JobParametersConverter in JobOperationsController,
24+
// just add a bean of that type to the JobParametersConverter, like in the following code.
25+
// This starter's implementation will step aside then.
26+
// @Bean
27+
// public JobParametersConverter jobParametersConverter(){
28+
// return new MyOwnJobParametersConverter();
29+
// }
30+
2231
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET http://localhost:8081/batch/monitoring/jobs
2+
Content-Type: application/json
3+
4+
###
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
POST http://localhost:8081/batch/jobs/job
2+
Content-Type: application/json
3+
4+
{}
5+
6+
###

0 commit comments

Comments
 (0)