|
1 | 1 | # spring-batch-rest |
2 | 2 |
|
3 | | -[](https://search.maven.org/artifact/com.github.chrisgleissner/spring-batch-rest-api) |
| 3 | +[](https://maven-badges.herokuapp.com/maven-central/com/github/chrisgleissner/spring-batch-rest-api) |
4 | 4 | [](https://www.javadoc.io/doc/com.github.chrisgleissner/spring-batch-rest-api) |
5 | 5 | [](https://travis-ci.org/chrisgleissner/spring-batch-rest) |
6 | 6 | [](https://coveralls.io/github/chrisgleissner/spring-batch-rest?branch=master) |
@@ -55,37 +55,70 @@ Here's how to run a <a href="https://github.com/chrisgleissner/spring-batch-rest |
55 | 55 |
|
56 | 56 | ## Getting Started |
57 | 57 |
|
58 | | -To integrate the REST API in your Spring Boot project, first add a dependency for Maven: |
| 58 | +To integrate the REST API in your Spring Boot project, first ensure you have an entry point to your application such as |
| 59 | + |
| 60 | +```java |
| 61 | +@SpringBootApplication |
| 62 | +public class SpringBootApp { |
| 63 | + public static void main(String[] args) { |
| 64 | + SpringApplication.run(SpringBootApp.class, args); |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +Then, simply add one of the following two dependencies to your project: |
59 | 70 |
|
| 71 | +### Core API |
| 72 | + |
| 73 | +The `spring-batch-rest-api` dependency comes with `jobs` and `jobExecutions` REST endpoints. It is recommended if you |
| 74 | +don't require Quartz for scheduling your jobs. |
| 75 | + |
| 76 | +Maven: |
60 | 77 | ```xml |
61 | 78 | <dependency> |
62 | 79 | <groupId>com.github.chrisgleissner</groupId> |
63 | 80 | <artifactId>spring-batch-rest-api</artifactId> |
64 | | - <version>1.3.0</version> |
| 81 | + <version>VERSION</version> |
65 | 82 | </dependency> |
66 | 83 | ``` |
67 | 84 |
|
68 | | -or Gradle: |
| 85 | +Gradle: |
69 | 86 | ``` |
70 | | -implementation 'com.github.chrisgleissner:spring-batch-rest-api:1.3.0' |
| 87 | +implementation 'com.github.chrisgleissner:spring-batch-rest-api:VERSION' |
71 | 88 | ``` |
72 | 89 |
|
73 | | -Then add `@EnableSpringBatchRest` to your Spring Boot application class, for <a href="https://github.com/chrisgleissner/spring-batch-rest/blob/master/example/src/main/java/com/github/chrisgleissner/springbatchrest/example/SpringBatchRestSampleApplication.java">example</a>: |
74 | | -```java |
75 | | -@SpringBootApplication |
76 | | -@EnableSpringBatchRest |
77 | | -public class SpringBatchRestSampleApplication { |
78 | | - public static void main(String[] args) { |
79 | | - SpringApplication.run(SpringBatchRestSampleApplication.class, args); |
80 | | - } |
81 | | -} |
| 90 | +### Quartz API |
| 91 | + |
| 92 | +The `spring-batch-rest-quartz-api` dependency includes everything above and and additionally exposes Quartz schedules |
| 93 | +via the `jobDetails` REST endpoint. |
| 94 | + |
| 95 | +Maven: |
| 96 | +```xml |
| 97 | +<dependency> |
| 98 | + <groupId>com.github.chrisgleissner</groupId> |
| 99 | + <artifactId>spring-batch-rest-quartz-api</artifactId> |
| 100 | + <version>VERSION</version> |
| 101 | +</dependency> |
| 102 | +``` |
| 103 | + |
| 104 | +Gradle: |
| 105 | +``` |
| 106 | +implementation 'com.github.chrisgleissner:spring-batch-rest-quartz-api:VERSION' |
| 107 | +``` |
| 108 | + |
| 109 | +### See it in Action |
| 110 | + |
| 111 | +To see `spring-batch-rest-api` in action, run |
| 112 | +```text |
| 113 | +mvn install -Dmaven.test.skip; java -jar example/api/target/*.jar |
82 | 114 | ``` |
83 | 115 |
|
84 | | -To see this example in action, run |
| 116 | +For `spring-batch-rest-quartz-api`, run |
85 | 117 | ```text |
86 | | -mvn install -Dmaven.test.skip; java -jar example/target/*.jar |
| 118 | +mvn install -Dmaven.test.skip; java -jar example/quartz-api/target/*.jar |
87 | 119 | ``` |
88 | | -and then check the Swagger REST API docs at |
| 120 | + |
| 121 | +Once it's up, check the Swagger REST API docs at |
89 | 122 | <a href="http://localhost:8080/swagger-ui.html">http://localhost:8080/swagger-ui.html</a>. |
90 | 123 |
|
91 | 124 |
|
@@ -126,6 +159,8 @@ The following REST endpoints are available: |
126 | 159 |
|
127 | 160 | ### Quartz Schedules |
128 | 161 |
|
| 162 | +As mentioned above, these endpoints are only exposed if you're using the `spring-batch-rest-api-quartz` dependency: |
| 163 | + |
129 | 164 | | HTTP Method | Path | Description | |
130 | 165 | |--------------|------------------------|--------------| |
131 | 166 | | GET | /jobDetails | All Quartz schedules | |
@@ -170,7 +205,23 @@ The cache only contains job executions since the Spring context creation, ie. it |
170 | 205 |
|
171 | 206 | Spring Batch prevents repeated invocations of a job unless you use different properties (aka job parameters) each time. To bypass this, a unique property (ie. a random UUID) is added to each job invocation. You can disable this by setting the property to false. |
172 | 207 |
|
| 208 | +### Disable Spring Batch REST API REST Endpoints |
| 209 | + |
| 210 | +`com.github.chrisgleissner.springbatchrest.enabled=false` (default: true) |
| 211 | + |
| 212 | +Useful if you only want to expose the REST API in certain environments. |
| 213 | + |
| 214 | +### Disable Swagger UI |
| 215 | + |
| 216 | +`springdoc.swagger-ui.enabled=false` (default: true) |
| 217 | + |
| 218 | +See https://github.com/springdoc/springdoc-openapi for further config options. |
| 219 | + |
| 220 | +### Disable Custom Exception Handling |
| 221 | + |
| 222 | +`com.github.chrisgleissner.springbatchrest.controllerAdvice=false` (default: true) |
173 | 223 |
|
| 224 | +This disables the global exception handling via `com.github.chrisgleissner.springbatchrest.api.core.jobexecution.ResponseExceptionHandler`. |
174 | 225 |
|
175 | 226 | ## Job Property Overrides |
176 | 227 |
|
@@ -202,21 +253,21 @@ If a property is not overridden, it is resolved against the Spring environment. |
202 | 253 |
|
203 | 254 | The <a href="https://github.com/chrisgleissner/spring-batch-rest/tree/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util">util module</a> contains code for registering, starting and scheduling jobs: |
204 | 255 |
|
205 | | -[JobBuilder](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/adhoc/JobBuilder.java) builds a simple job based on a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runnable.html">Runnable</a>: |
| 256 | +[JobBuilder](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/core/JobBuilder.java) builds a simple job based on a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runnable.html">Runnable</a>: |
206 | 257 |
|
207 | 258 | ```java |
208 | 259 | Job job = jobBuilder.createJob("jobName", () -> System.out.println("Running job")); |
209 | 260 | ``` |
210 | 261 |
|
211 | | -[AdHocScheduler](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/adhoc/AdHocScheduler.java) registers and triggers a job using a Quartz CRON trigger. This can be performed at |
| 262 | +[AdHocScheduler](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/quartz/AdHocScheduler.java) registers and triggers a job using a Quartz CRON trigger. This can be performed at |
212 | 263 | run-time rather than Spring wiring time which allows for simplified set-up of a large number of jobs that only |
213 | 264 | differ slightly: |
214 | 265 |
|
215 | 266 | ```java |
216 | 267 | adHocScheduler.schedule("jobName", job, "0/30 * * * * ?"); |
217 | 268 | ``` |
218 | 269 |
|
219 | | -[AdHocStarter](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/adhoc/AdHocStarter.java) is similar to AdHocScheduler, but used for immediately starting a job: |
| 270 | +[AdHocStarter](https://github.com/chrisgleissner/spring-batch-rest/blob/master/util/src/main/java/com/github/chrisgleissner/springbatchrest/util/core/AdHocStarter.java) is similar to AdHocScheduler, but used for immediately starting a job: |
220 | 271 |
|
221 | 272 | ```java |
222 | 273 | adHocStarter.start("jobName", job); |
|
0 commit comments