Skip to content

Commit 3c6e55f

Browse files
Merge pull request #8 from chrisgleissner/feature/decoupled-core-and-quartz
Decoupled core and quartz
2 parents 944a7fa + f45980c commit 3c6e55f

File tree

74 files changed

+1017
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1017
-307
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
language: java
2-
2+
install: true
33
cache:
44
directories:
55
- $HOME/.m2
6-
76
jdk:
87
- openjdk11
9-
108
script:
119
- mvn clean install -Pjacoco coveralls:report

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: java -Dserver.port=$PORT $JAVA_OPTS -jar example/target/*.jar
1+
web: java -Dserver.port=$PORT $JAVA_OPTS -jar example/quartz-api/target/*.jar

README.md

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# spring-batch-rest
22

3-
[![Maven Central](https://img.shields.io/maven-metadata/v/http/central.maven.org/maven2/com/github/chrisgleissner/spring-batch-rest-api/maven-metadata.xml.svg)](https://search.maven.org/artifact/com.github.chrisgleissner/spring-batch-rest-api)
3+
[![Maven Central](https://img.shields.io/maven-central/v/com.github.chrisgleissner/spring-batch-rest-api)](https://maven-badges.herokuapp.com/maven-central/com/github/chrisgleissner/spring-batch-rest-api)
44
[![Javadocs](https://www.javadoc.io/badge/com.github.chrisgleissner/spring-batch-rest-api.svg)](https://www.javadoc.io/doc/com.github.chrisgleissner/spring-batch-rest-api)
55
[![Build Status](https://travis-ci.org/chrisgleissner/spring-batch-rest.svg?branch=master)](https://travis-ci.org/chrisgleissner/spring-batch-rest)
66
[![Coverage Status](https://coveralls.io/repos/github/chrisgleissner/spring-batch-rest/badge.svg?branch=master)](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
5555

5656
## Getting Started
5757

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:
5970

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:
6077
```xml
6178
<dependency>
6279
<groupId>com.github.chrisgleissner</groupId>
6380
<artifactId>spring-batch-rest-api</artifactId>
64-
<version>1.3.0</version>
81+
<version>VERSION</version>
6582
</dependency>
6683
```
6784

68-
or Gradle:
85+
Gradle:
6986
```
70-
implementation 'com.github.chrisgleissner:spring-batch-rest-api:1.3.0'
87+
implementation 'com.github.chrisgleissner:spring-batch-rest-api:VERSION'
7188
```
7289

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
82114
```
83115

84-
To see this example in action, run
116+
For `spring-batch-rest-quartz-api`, run
85117
```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
87119
```
88-
and then check the Swagger REST API docs at
120+
121+
Once it's up, check the Swagger REST API docs at
89122
<a href="http://localhost:8080/swagger-ui.html">http://localhost:8080/swagger-ui.html</a>.
90123

91124

@@ -126,6 +159,8 @@ The following REST endpoints are available:
126159

127160
### Quartz Schedules
128161

162+
As mentioned above, these endpoints are only exposed if you're using the `spring-batch-rest-api-quartz` dependency:
163+
129164
| HTTP Method | Path | Description |
130165
|--------------|------------------------|--------------|
131166
| GET | /jobDetails | All Quartz schedules |
@@ -170,7 +205,23 @@ The cache only contains job executions since the Spring context creation, ie. it
170205

171206
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.
172207

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)
173223

224+
This disables the global exception handling via `com.github.chrisgleissner.springbatchrest.api.core.jobexecution.ResponseExceptionHandler`.
174225

175226
## Job Property Overrides
176227

@@ -202,21 +253,21 @@ If a property is not overridden, it is resolved against the Spring environment.
202253

203254
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:
204255

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>:
206257

207258
```java
208259
Job job = jobBuilder.createJob("jobName", () -> System.out.println("Running job"));
209260
```
210261

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
212263
run-time rather than Spring wiring time which allows for simplified set-up of a large number of jobs that only
213264
differ slightly:
214265

215266
```java
216267
adHocScheduler.schedule("jobName", job, "0/30 * * * * ?");
217268
```
218269

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:
220271

221272
```java
222273
adHocStarter.start("jobName", job);

api/pom.xml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<groupId>com.github.chrisgleissner</groupId>
88
<artifactId>spring-batch-rest</artifactId>
9-
<version>1.3.1-SNAPSHOT</version>
9+
<version>1.4.1-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>spring-batch-rest-api</artifactId>
13-
<version>1.3.1-SNAPSHOT</version>
13+
<version>1.4.1-SNAPSHOT</version>
1414
<name>spring-batch-rest-api</name>
1515

1616
<dependencies>
@@ -40,7 +40,7 @@
4040
<dependency>
4141
<groupId>org.springdoc</groupId>
4242
<artifactId>springdoc-openapi-ui</artifactId>
43-
<version>1.2.29</version>
43+
<version>1.2.33</version>
4444
</dependency>
4545
<dependency>
4646
<groupId>org.projectlombok</groupId>
@@ -60,10 +60,6 @@
6060
<groupId>org.springframework.boot</groupId>
6161
<artifactId>spring-boot-starter-hateoas</artifactId>
6262
</dependency>
63-
<dependency>
64-
<groupId>org.springframework.boot</groupId>
65-
<artifactId>spring-boot-starter-quartz</artifactId>
66-
</dependency>
6763
<dependency>
6864
<groupId>org.springframework.boot</groupId>
6965
<artifactId>spring-boot-starter-thymeleaf</artifactId>
@@ -78,4 +74,30 @@
7874
<scope>test</scope>
7975
</dependency>
8076
</dependencies>
77+
78+
<build>
79+
<plugins>
80+
<plugin>
81+
<artifactId>maven-enforcer-plugin</artifactId>
82+
<version>3.0.0-M3</version>
83+
<executions>
84+
<execution>
85+
<id>enforce-versions</id>
86+
<goals>
87+
<goal>enforce</goal>
88+
</goals>
89+
<configuration>
90+
<rules>
91+
<bannedDependencies>
92+
<excludes>
93+
<exclude>org.quartz-scheduler</exclude>
94+
</excludes>
95+
</bannedDependencies>
96+
</rules>
97+
</configuration>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
</plugins>
102+
</build>
81103
</project>

api/src/main/java/com/github/chrisgleissner/springbatchrest/api/EnableSpringBatchRest.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.chrisgleissner.springbatchrest.api.core;
2+
3+
public interface Constants {
4+
String REST_API_ENABLED = "com.github.chrisgleissner.springbatchrest.enabled";
5+
}

api/src/main/java/com/github/chrisgleissner/springbatchrest/api/SpringBatchRestConfiguration.java renamed to api/src/main/java/com/github/chrisgleissner/springbatchrest/api/core/SpringBatchRestCoreAutoConfiguration.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
package com.github.chrisgleissner.springbatchrest.api;
1+
package com.github.chrisgleissner.springbatchrest.api.core;
22

3-
import com.github.chrisgleissner.springbatchrest.api.job.JobController;
4-
import com.github.chrisgleissner.springbatchrest.api.jobdetail.JobDetailController;
5-
import com.github.chrisgleissner.springbatchrest.api.jobexecution.JobExecutionController;
6-
import com.github.chrisgleissner.springbatchrest.util.adhoc.AdHocStarter;
3+
import com.github.chrisgleissner.springbatchrest.api.core.job.JobController;
4+
import com.github.chrisgleissner.springbatchrest.api.core.jobexecution.JobExecutionController;
5+
import com.github.chrisgleissner.springbatchrest.util.core.AdHocStarter;
76
import io.swagger.v3.oas.models.Components;
87
import io.swagger.v3.oas.models.OpenAPI;
98
import io.swagger.v3.oas.models.info.Info;
109
import io.swagger.v3.oas.models.info.License;
1110
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
1211
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
13+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1314
import org.springframework.boot.info.BuildProperties;
1415
import org.springframework.context.annotation.Bean;
1516
import org.springframework.context.annotation.ComponentScan;
1617
import org.springframework.context.annotation.Configuration;
1718

19+
import static com.github.chrisgleissner.springbatchrest.api.core.Constants.REST_API_ENABLED;
20+
1821
@Configuration
1922
@EnableBatchProcessing
20-
@ComponentScan(basePackageClasses= {AdHocStarter.class, JobController.class, JobDetailController.class, JobExecutionController.class })
21-
public class SpringBatchRestConfiguration {
23+
@ConditionalOnProperty(name = REST_API_ENABLED, havingValue = "true", matchIfMissing = true)
24+
@ComponentScan(basePackageClasses= {AdHocStarter.class, JobController.class, JobExecutionController.class })
25+
public class SpringBatchRestCoreAutoConfiguration {
2226

2327
@Autowired(required = false)
2428
BuildProperties buildProperties;
2529

2630
@Bean
31+
@ConditionalOnMissingBean
2732
public OpenAPI customOpenAPI() {
2833
return new OpenAPI()
2934
.components(new Components())

api/src/main/java/com/github/chrisgleissner/springbatchrest/api/job/Job.java renamed to api/src/main/java/com/github/chrisgleissner/springbatchrest/api/core/job/Job.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.chrisgleissner.springbatchrest.api.job;
1+
package com.github.chrisgleissner.springbatchrest.api.core.job;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Value;

api/src/main/java/com/github/chrisgleissner/springbatchrest/api/job/JobController.java renamed to api/src/main/java/com/github/chrisgleissner/springbatchrest/api/core/job/JobController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package com.github.chrisgleissner.springbatchrest.api.job;
1+
package com.github.chrisgleissner.springbatchrest.api.core.job;
22

33
import io.swagger.v3.oas.annotations.Operation;
44
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
56
import org.springframework.hateoas.CollectionModel;
67
import org.springframework.web.bind.annotation.GetMapping;
78
import org.springframework.web.bind.annotation.PathVariable;
@@ -10,10 +11,12 @@
1011

1112
import java.util.Collection;
1213

14+
import static com.github.chrisgleissner.springbatchrest.api.core.Constants.REST_API_ENABLED;
1315
import static java.util.stream.Collectors.toList;
1416
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
1517
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
1618

19+
@ConditionalOnProperty(name = REST_API_ENABLED, havingValue = "true", matchIfMissing = true)
1720
@RestController
1821
@RequestMapping(value = "/jobs", produces = "application/hal+json")
1922
public class JobController {

api/src/main/java/com/github/chrisgleissner/springbatchrest/api/job/JobResource.java renamed to api/src/main/java/com/github/chrisgleissner/springbatchrest/api/core/job/JobResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.chrisgleissner.springbatchrest.api.job;
1+
package com.github.chrisgleissner.springbatchrest.api.core.job;
22

33
import org.springframework.hateoas.RepresentationModel;
44

0 commit comments

Comments
 (0)