我在一个现有的应用程序中集成了Spring Batch,而其他bean也成功地使用了DataSourceTransactionManager
。但是,当我引入@EnableBatchProcessing
注解时,我得到了以下错误:
AuthBeans中的字段事务管理器需要一个类型为“org.springframework.jdbc.datasource.DataSourceTransactionManager”的Bean,但找不到该Bean。
我已经尝试配置BatchConfigurer
,但它没有解决问题。请查看下面的BatchConfigurer
代码。
@Configuration
public class CustomBatchConfigurer implements BatchConfigurer {
@Autowired
private DataSource dataSource;
@Override
public JobRepository getJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(dataSource);
factory.setTransactionManager(getTransactionManager());
factory.afterPropertiesSet();
return (JobRepository) factory.getObject();
}
@Override
public PlatformTransactionManager getTransactionManager() throws Exception {
return new DataSourceTransactionManager(dataSource);
}
@Override
public JobLauncher getJobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(getJobRepository());
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
@Override
public JobExplorer getJobExplorer() throws Exception {
JobExplorerFactoryBean factory = new JobExplorerFactoryBean();
factory.setDataSource(dataSource);
factory.afterPropertiesSet();
return (JobExplorer) factory.getObject();
}
我想知道我错过了什么吗?你的帮助,这将是非常感谢。
1条答案
按热度按时间oxf4rvwz1#
在哪个类中,您保留了
@EnableBatchProcessing
注解。@EnableBatchProcessing
应该位于最高级别。默认情况下,
@EnableBatchProcessing
将创建DataSourceTransactionManager
。通过这个BatchConfigure并遵循example。
我希望这将解决您的问题。