Reputation: 2291
I have a java spring application that uses it's postgres db, it's no prob. But also I have a quartz job that runs every hour and syncing data from other mysql DS with postgres. The issue is JDBC connection string is dynamic and is being changed, I can't just specify it on systemstartup, etc. How to do that gracefully? I mean take jdbc connection string, connect to db and retrieve data from there? I also use spring-data there.
Upvotes: 0
Views: 100
Reputation: 2143
One possible solution is to use spring batch @JobScope beans and have your quartz job launch the spring batch job.
You can configure a datasource to have @JobScope and this would then make spring create that datasource each time the job is executed. You can then use job parameters or other variables to create the specific datasource that you want. An example of a configuration class that creates a datasource like this is below...
@Configuration
public class JobDatabaseConfiguration {
@Bean
@JobScope
public DataSource jobDataSource() throws IOException {
// set these from job parameters...
String jdbcUrl = "<your jdbc url>";
String driver = "<your driver>";
String user = "user";
String password = "password";
return DataSourceBuilder.create()
.driverClassName(driver)
.url(jdbcUrl)
.username(user)
.password(password)
build();
}
}
Upvotes: 1