I am writing a spring cloud task(Spring Boot 3, Java 17) that reads a flat file and inserts it into a database. So this is a multiple databases scenario. Running via SpringCloud dataflow server 2.112, it fails with " Invalid TaskExecution, ID ". Please see the exception below.
Can someone please point out where I am going wrong? I have tried debugging it and I noticed that tablePrefix is "TASK_" always and not "BOOT3_TASK_"
Your assistance would be greatly appreciated.
Exception:
Caused by: java.lang.IllegalArgumentException: Invalid TaskExecution, ID 50 not found
at org.springframework.util.Assert.notNull(Assert.java:172) ~[spring-core-6.1.3.jar!/:6.1.3]
at org.springframework.cloud.task.listener.TaskLifecycleListener.doTaskStart(TaskLifecycleListener.java:184) ~[!/:0.0.1-SNAPSHOT]
at org.springframework.cloud.task.listener.TaskLifecycleListener.start(TaskLifecycleListener.java:312) ~[!/:0.0.1-SNAPSHOT]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:284) ~[spring-context-6.1.3.jar!/:6.1.3]
... 19 common frames omitted
application.yml
spring:
datasource-scdf:
url: "jdbc:postgresql://localhost:5432/dataflow?schema=public"
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
hikari:
jdbc-url: "jdbc:postgresql://localhost:5432/dataflow?schema=public"
datasource-app:
url: "jdbc:mysql://localhost:3306/test_task"
username: root
password:
driver-class-name: com.mysql.cj.jdbc.Driver
Datasource Configuration
@Configuration
public class CustomCloudTaskConfiguration {
@Bean
@ConfigurationProperties("spring.datasource-scdf")
public DataSourceProperties customOperationsDataSourceProperties() {
return new DataSourceProperties();
}
@Bean(name = "customDatasource")
@ConfigurationProperties("spring.datasource-scdf.configuration")
public DataSource customOperationsDataSource() {
return customOperationsDataSourceProperties()
.initializeDataSourceBuilder()
.type( HikariDataSource.class )
.build();
}
@Primary
@Bean
public DataSourceTransactionManager taskOperationsTransactionManager() {
return new DataSourceTransactionManager( customOperationsDataSource() );
}
}
DefaultTaskConfigurer
@Component
public class CustomTaskConfigurer extends DefaultTaskConfigurer {
public CustomTaskConfigurer(@Qualifier("customDatasource") DataSource dataSource) {
super(dataSource);
}
}
I have tried setting the table Prefix through Spring profile, but no luck
Fix
@Component
public class CustomTaskConfigurer extends DefaultTaskConfigurer {
@Autowired
public CustomTaskConfigurer(@Qualifier("springCloudDataSource") DataSource dataSource, TaskProperties taskProperties, ApplicationContext context) {
super(dataSource, taskProperties.getTablePrefix(),context);
}
}
Also ensure the database configuration properties/name defined in the task matches with what SCDF server is passing upon execution
It is very important that your Task application is registered with bootVersion=3
The REST docs provides more info: https://docs.spring.io/spring-cloud-dataflow/docs/2.11.2/reference/htmlsingle/#resources-app-registry-post
On the dashboard registration page there is a dropdown for the Boot Version.
You can find more info on Boot 3.x support