0
我想創建一個這樣的bean:初始化Spring Batch的DB之前,應用程序bean創建
@Bean
public Clock clock(JobExplorer explorer, Environment environment) {
// Check last run time of job and create a Clock bean
}
但是,當應用程序啓動時,我得到的錯誤:ORA-00942: table or view does not exist
因爲彈簧批模式不是招」 t由spring boot的BatchAutoConfiguration
創建。
於是,我試着這樣做:
@Bean
@ConditionOnBean(BatchDatabaseInitializer.class)
public Clock clock(JobExplorer explorer, Environment environment) {
// Check last run time of job and create a Clock bean
}
這種轉移時鐘豆創建要求Clock
一個bean創建時從錯誤:
@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
這可以保持級聯。如果我在itemReader
方法中輸入@ConditionalOnBean
,那麼當創建一個需要itemReader
的bean時,我會得到相同的「無限定bean」錯誤。
那麼,如何在創建bean之前確保spring批處理模式已初始化?
是的。這工作。 'ConditionOnBean(YourBean.class)'是spring-boot項目的一部分。我誤解了它的用法。 – 2015-04-01 12:20:15