Skip to content

Commit 1cc6f61

Browse files
committed
Update Task to BOOT 2.1.M1
Migrating to use ApplicationContextRunner or ImportAutoConfiguration with SpringApp.run, instead of SpringApplicationBuilder, because builder does not handle AutoConfiguration properly SimpleTaskAutoConfiguration now has an annotation AutoConfigureBefore the BatchTaskAutoConfig so that it is processed prior. THis is so that that BatchTaskAutoConfig can create the appropriate beans SimpleTaskAutoConfiguration has new annotations so that it is AutoConfigured after BindingServiceConfiguration and after SimpleTaskAutoConfiguration. This is so that it does not attempt to start emitting messages before stream is ready and it can create the appropriate beans after SimpleTaskAutoConfiguration has run. Renamed SimpleTaskConfiguration to SimpleTaskAutoConfiguration. Task version updated to 2.1.0 Added missing headers Resolves spring-cloud#439 Resolves spring-cloud#440 polish Updated documentation. Deprecated EnableTask Added ability to disable Task autoconfiguration. Removed @EnableTask from tests
1 parent 1406fa9 commit 1cc6f61

File tree

58 files changed

+616
-560
lines changed

Some content is hidden

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

58 files changed

+616
-560
lines changed

README.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ $ ./mvnw clean install
2323
[source,java,indent=2]
2424
----
2525
@SpringBootApplication
26-
@EnableTask
2726
public class MyApp {
2827
2928
@Bean

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<parent>
66
<groupId>org.springframework.cloud</groupId>
77
<artifactId>spring-cloud-build</artifactId>
8-
<version>2.0.0.RELEASE</version>
8+
<version>2.1.0.BUILD-SNAPSHOT</version>
99
<relativePath />
1010
</parent>
1111

1212
<groupId>org.springframework.cloud</groupId>
1313
<artifactId>spring-cloud-task-parent</artifactId>
14-
<version>2.0.1.BUILD-SNAPSHOT</version>
14+
<version>2.1.0.BUILD-SNAPSHOT</version>
1515
<packaging>pom</packaging>
1616
<name>Spring Cloud Task Build</name>
1717
<description>Spring Cloud Task Build</description>
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>org.springframework.cloud</groupId>
5959
<artifactId>spring-cloud-task-dependencies</artifactId>
60-
<version>2.0.1.BUILD-SNAPSHOT</version>
60+
<version>2.1.0.BUILD-SNAPSHOT</version>
6161
<type>pom</type>
6262
<scope>import</scope>
6363
</dependency>
@@ -132,10 +132,10 @@
132132
</modules>
133133

134134
<properties>
135-
<spring-cloud-stream.version>2.0.0.RELEASE</spring-cloud-stream.version>
135+
<spring-cloud-stream.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-stream.version>
136136
<spring-cloud-deployer-spi.version>1.3.2.RELEASE</spring-cloud-deployer-spi.version>
137137
<spring-cloud-deployer-local.version>1.3.5.RELEASE</spring-cloud-deployer-local.version>
138-
<spring-cloud-stream-binder-rabbit.version>2.0.0.RELEASE</spring-cloud-stream-binder-rabbit.version>
138+
<spring-cloud-stream-binder-rabbit.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-stream-binder-rabbit.version>
139139
<spring-cloud-deployer-resource-support.version>1.3.2.RELEASE</spring-cloud-deployer-resource-support.version>
140140
<spring-cloud-deployer-resource-maven.version>1.3.2.RELEASE</spring-cloud-deployer-resource-maven.version>
141141
<spring-batch.version>4.0.1.RELEASE</spring-batch.version>

spring-cloud-starter-task/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.cloud</groupId>
88
<artifactId>spring-cloud-task-parent</artifactId>
9-
<version>2.0.1.BUILD-SNAPSHOT</version>
9+
<version>2.1.0.BUILD-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>spring-cloud-starter-task</artifactId>

spring-cloud-task-batch/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.cloud</groupId>
88
<artifactId>spring-cloud-task-parent</artifactId>
9-
<version>2.0.1.BUILD-SNAPSHOT</version>
9+
<version>2.1.0.BUILD-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>spring-cloud-task-batch</artifactId>

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherCommandLineRunnerTests.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@
3232
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3333
import org.springframework.beans.factory.annotation.Autowired;
3434
import org.springframework.boot.SpringApplication;
35+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
3536
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
3637
import org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner;
3738
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
3839
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
3940
import org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration;
4041
import org.springframework.cloud.task.batch.configuration.TaskJobLauncherAutoConfiguration;
41-
import org.springframework.cloud.task.configuration.EnableTask;
42+
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
43+
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
4244
import org.springframework.cloud.task.repository.TaskExecution;
4345
import org.springframework.cloud.task.repository.TaskExplorer;
4446
import org.springframework.context.ConfigurableApplicationContext;
4547
import org.springframework.context.annotation.Bean;
46-
import org.springframework.context.annotation.Configuration;
48+
import org.springframework.context.annotation.Import;
4749
import org.springframework.data.domain.Page;
4850
import org.springframework.data.domain.PageRequest;
4951

@@ -65,16 +67,13 @@ public void tearDown() {
6567

6668
@Test
6769
public void testTaskJobLauncherCLRSuccessFail() {
68-
String[] enabledArgs = new String[] { "--spring.cloud.task.batch.failOnJobFailure=true" };
70+
String[] enabledArgs = new String[] {
71+
"--spring.cloud.task.batch.failOnJobFailure=true",
72+
"--spring.batch.job.enabled=false"};// batch job enabled is turned to false so that we can use Task's JobLauncher
6973
boolean isExceptionThrown = false;
7074
try {
7175
this.applicationContext = SpringApplication
72-
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class,
73-
PropertyPlaceholderAutoConfiguration.class,
74-
EmbeddedDataSourceConfiguration.class,
75-
BatchAutoConfiguration.class,
76-
TaskBatchAutoConfiguration.class,
77-
TaskJobLauncherAutoConfiguration.class }, enabledArgs);
76+
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class}, enabledArgs);
7877
}
7978
catch (IllegalStateException exception) {
8079
isExceptionThrown = true;
@@ -86,16 +85,12 @@ public void testTaskJobLauncherCLRSuccessFail() {
8685
public void testTaskJobLauncherPickOneJob() {
8786
String[] enabledArgs = new String[] {
8887
"--spring.cloud.task.batch.failOnJobFailure=true",
89-
"--spring.cloud.task.batch.jobNames=jobSucceed" };
88+
"--spring.cloud.task.batch.jobNames=jobSucceed",
89+
"--spring.batch.job.enabled=false" }; // batch job enabled is turned to false so that we can use Task's JobLauncher
9090
boolean isExceptionThrown = false;
9191
try {
9292
this.applicationContext = SpringApplication
93-
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class,
94-
PropertyPlaceholderAutoConfiguration.class,
95-
EmbeddedDataSourceConfiguration.class,
96-
BatchAutoConfiguration.class,
97-
TaskBatchAutoConfiguration.class,
98-
TaskJobLauncherAutoConfiguration.class }, enabledArgs);
93+
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobWithFailureConfiguration.class }, enabledArgs);
9994
}
10095
catch (IllegalStateException exception) {
10196
isExceptionThrown = true;
@@ -108,12 +103,7 @@ public void testTaskJobLauncherPickOneJob() {
108103
public void testCommandLineRunnerSetToFalse() {
109104
String[] enabledArgs = new String[] { };
110105
this.applicationContext = SpringApplication
111-
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobConfiguration.class,
112-
PropertyPlaceholderAutoConfiguration.class,
113-
EmbeddedDataSourceConfiguration.class,
114-
BatchAutoConfiguration.class,
115-
TaskBatchAutoConfiguration.class,
116-
TaskJobLauncherAutoConfiguration.class }, enabledArgs);
106+
.run(new Class[] { TaskJobLauncherCommandLineRunnerTests.JobConfiguration.class }, enabledArgs);
117107
validateContext();
118108
assertThat(applicationContext.getBean(JobLauncherCommandLineRunner.class)).isNotNull();
119109
boolean exceptionThrown = false;
@@ -140,9 +130,15 @@ private void validateContext() {
140130

141131
}
142132

143-
@Configuration
144133
@EnableBatchProcessing
145-
@EnableTask
134+
@ImportAutoConfiguration({
135+
PropertyPlaceholderAutoConfiguration.class,
136+
BatchAutoConfiguration.class,
137+
TaskBatchAutoConfiguration.class,
138+
TaskJobLauncherAutoConfiguration.class,
139+
SingleTaskConfiguration.class,
140+
SimpleTaskAutoConfiguration.class })
141+
@Import(EmbeddedDataSourceConfiguration.class)
146142
public static class JobConfiguration {
147143

148144
@Autowired
@@ -166,9 +162,15 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
166162
}
167163
}
168164

169-
@Configuration
170165
@EnableBatchProcessing
171-
@EnableTask
166+
@ImportAutoConfiguration({
167+
PropertyPlaceholderAutoConfiguration.class,
168+
BatchAutoConfiguration.class,
169+
TaskBatchAutoConfiguration.class,
170+
TaskJobLauncherAutoConfiguration.class,
171+
SingleTaskConfiguration.class,
172+
SimpleTaskAutoConfiguration.class })
173+
@Import(EmbeddedDataSourceConfiguration.class)
172174
public static class JobWithFailureConfiguration {
173175

174176
@Autowired

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/listener/PrefixTests.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
import org.springframework.batch.repeat.RepeatStatus;
3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.boot.SpringApplication;
32+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
3233
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration;
3334
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
3435
import org.springframework.cloud.task.batch.configuration.TaskBatchAutoConfiguration;
35-
import org.springframework.cloud.task.configuration.EnableTask;
36+
import org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration;
37+
import org.springframework.cloud.task.configuration.SingleTaskConfiguration;
3638
import org.springframework.cloud.task.repository.TaskExplorer;
3739
import org.springframework.context.ConfigurableApplicationContext;
3840
import org.springframework.context.annotation.Bean;
@@ -58,11 +60,8 @@ public void tearDown() {
5860

5961
@Test
6062
public void testPrefix() {
61-
this.applicationContext = SpringApplication.run(new Class[] {
62-
JobConfiguration.class,
63-
PropertyPlaceholderAutoConfiguration.class,
64-
BatchAutoConfiguration.class,
65-
TaskBatchAutoConfiguration.class }, new String[] { "--spring.cloud.task.tablePrefix=FOO_" });
63+
this.applicationContext = SpringApplication.run(
64+
JobConfiguration.class, new String[] { "--spring.cloud.task.tablePrefix=FOO_" });
6665

6766
TaskExplorer taskExplorer = this.applicationContext.getBean(TaskExplorer.class);
6867

@@ -73,7 +72,11 @@ public void testPrefix() {
7372

7473
@Configuration
7574
@EnableBatchProcessing
76-
@EnableTask
75+
@ImportAutoConfiguration({ PropertyPlaceholderAutoConfiguration.class,
76+
BatchAutoConfiguration.class,
77+
TaskBatchAutoConfiguration.class,
78+
SimpleTaskAutoConfiguration.class,
79+
SingleTaskConfiguration.class })
7780
public static class JobConfiguration {
7881

7982
@Autowired

0 commit comments

Comments
 (0)