To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2
来源:互联网 发布:淘宝的手办店 编辑:程序博客网 时间:2024/05/06 06:49
1、问题背景:
项目中用@Configuration配置了两个DataSource数据源Bean。
两个dataSource也分别指定了name,并用@Primary标注了其中一个数据源,代码如下:
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Primary;import org.springframework.core.env.Environment;import org.springframework.jdbc.core.JdbcTemplate;import javax.sql.DataSource;@Configurationpublic class SourceConfiguration { @Autowired private Environment env; @Primary @Bean(name = "originalDataSource") public DataSource originalDataSource() { return DataSourceBuilder.create() .url(env.getProperty("original.datasource.url")) .driverClassName(env.getProperty("original.datasource.driverClassName")) .username(env.getProperty("original.datasource.username")) .password(env.getProperty("original.datasource.password")) .build(); } @Bean(name = "destDataSource") public DataSource destDataSource() { return DataSourceBuilder.create() .url(env.getProperty("dest.datasource.url")) .driverClassName(env.getProperty("dest.datasource.driverClassName")) .username(env.getProperty("dest.datasource.username")) .password(env.getProperty("dest.datasource.password")) .build(); } @Bean public JdbcTemplate originalJdbcTemplate() { return new JdbcTemplate(originalDataSource()); } @Bean public JdbcTemplate destJdbcTemplate() { return new JdbcTemplate(destDataSource()); }}2、报错信息:
程序执行时出现报错:Caused by: java.lang.IllegalStateException: To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2
3、问题解决:
新增如下BatchConfigurer的Bean,返回DefaultBatchConfigurer(dataSource)对象,则程序运行正常:
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.Primary;import org.springframework.core.env.Environment;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;import org.springframework.batch.core.configuration.annotation.BatchConfigurer;import javax.sql.DataSource;@Configurationpublic class SourceConfiguration { @Autowired private Environment env; @Primary @Bean(name = "originalDataSource") public DataSource originalDataSource() { return DataSourceBuilder.create() .url(env.getProperty("original.datasource.url")) .driverClassName(env.getProperty("original.datasource.driverClassName")) .username(env.getProperty("original.datasource.username")) .password(env.getProperty("original.datasource.password")) .build(); } @Bean(name = "destDataSource") public DataSource destDataSource() { return DataSourceBuilder.create() .url(env.getProperty("dest.datasource.url")) .driverClassName(env.getProperty("dest.datasource.driverClassName")) .username(env.getProperty("dest.datasource.username")) .password(env.getProperty("dest.datasource.password")) .build(); } @Bean public JdbcTemplate originalJdbcTemplate() { return new JdbcTemplate(originalDataSource()); } @Bean public JdbcTemplate destJdbcTemplate() { return new JdbcTemplate(destDataSource()); } @Bean BatchConfigurer configurer(DataSource dataSource) { return new DefaultBatchConfigurer(dataSource); }}
0 0
- To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2
- SpringBatch异常To use the default BatchConfigurer the context must contain no more thanone DataSource
- 命令行 android 出 No suitable Java found. In order to properly use the Android Developer
- No context type was found in the assembly
- How to use Events in the Context of C#
- 解决错误ERROR: No suitable Java found. In order to properly use the Android Developer Tools,…
- Error occurred running Grails CLI: No profile found for name [web]. (Use --stacktrace to see the ful
- 多模块项目Module must not contain source root. The root already belongs to module
- Unable to configure Windows to Trust the Fiddler Root certificate.The LOG tab may contain more infor
- No unexpired provisioning profiles found that contain any of the keychain's signing certificates
- SpringMVC的数据库配置dataSource报错处理:The reference to entity "characterEncoding" must end with the ';' deli
- 关于J2ME运行时报MUST contain the attribute: MIDlet-1
- 2 scenarios to use the static modifier
- catkin_make install 报错 The manifest (with format version 2) must not contain the following tags: run
- How to use the date format that has been setup as default in Settings?
- MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT’
- Server 2008 R2: “You must use the Role Management Tool to install or configure Microsoft .NET”
- Server 2008 R2: “You must use the Role Management Tool to install or configure Microsoft .NET”
- java正则验证电话,手机,邮箱,日期,金额
- 第71篇一对多之优化实时共享私有白板最后一页(二)添加了一个老师辅导按钮
- mac版 navicat for mysql
- PAT 1127
- MyBatis的几种批量操作
- To use the default BatchConfigurer the context must contain no more thanone DataSource, found 2
- 由train_val.prototxt 生成deploy.prototxt
- [HNOI2002] 营业额统计(平衡树splay)
- 《java集合》--LinkedList
- c++第二次作业
- Struts2操作普通属性与方法
- oracle之存储过程4-存储过程变量的使用
- Android Studio AIDL List 传递数据
- java中Collections.sort排序详解