Reputation: 15109
I'm trying to create a bean like so:
@Bean
public Clock clock(JobExplorer explorer, Environment environment) {
// Check last run time of job and create a Clock bean
}
But when the application starts up, I get the error: ORA-00942: table or view does not exist
because the spring batch schema hasn't been created by spring boot's BatchAutoConfiguration
yet.
Then, I tried to do this:
@Bean
@ConditionOnBean(BatchDatabaseInitializer.class)
public Clock clock(JobExplorer explorer, Environment environment) {
// Check last run time of job and create a Clock bean
}
This shifted the error from when clock bean was created to when a bean requiring Clock
was created:
@Bean(name = "reader")
public ItemReader<Record> itemReader(
JdbcTemplate jdbcTemplate, Clock clock) {
// Create item reader
}
Error: No qualifying bean of type [java.time.Clock] found for dependency
This keeps cascading. If I put a @ConditionalOnBean
on itemReader
method, then when a bean that requires itemReader
is created, I get the same "No qualifying bean" error.
So, How do I make sure that spring batch schema is initialized before my beans are created?
Upvotes: 0
Views: 732
Reputation: 5004
have you tried to use @DependsOn()
annotation? I was not aware of ConditionOnBean..
Upvotes: 1