0
votes

I configured two data sources in my app following the guide of spring example:https://github.com/spring-cloud/spring-cloud-task/blob/master/spring-cloud-task-samples/multiple-datasources. The spring boot version I use is :2.0.0.RELEASE The spring.cloud.task.version I use is :1.2.2.RELEASE.

This application works fine in my local computer, But when deploy to the to AWS, I got the following error with the defination of class:CustomTaskConfigurer.java. which defined the same as here:https://github.com/spring-cloud/spring-cloud-task/blob/master/spring-cloud-task-samples/multiple-datasources/src/main/java/io/spring/configuration/CustomTaskConfigurer.java

The error message is like below:

exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.task.configuration.SimpleTaskConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customTaskConfigurer' defined in file [/home/vcap/app/BOOT-INF/classes/com/xxx/configuration/CustomTaskConfigurer.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.xxx.configuration.CustomTaskConfigurer$$EnhancerBySpringCGLIB$$bc80cd46]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Unable to create a TaskExecutionDao.

2

2 Answers

0
votes

The root cause for this error is that when I developed the application locally I configure a local datasource bean for postgresql like below: @Bean @Primary @ConfigurationProperties("spring.datasource") public HikariDataSource sourceDataSource() { return DataSourceBuilder.create().type(HikariDataSource.class).build(); }

This bean read the properties in the application.properties file which identify the username and password url for the local postgres. When This application deloyed to cloud,It will connect to the cloud data base instead of the local databases, which means the url,username,and password are no longer correct. After add the configuration for cloud, this error disppeared.

But this exception stack trace only tell you that it is unable to create taskExecutionDao, It is really hard for the user to fix the issue when see such a error message

0
votes

If it is a multiple datasource issue, you can try marking it as @Primary. Providing a better stack trace is helpful.