gpt4 book ai didi

java - 无法将 SQLServerDriver 转换为 DataSource

转载 作者:行者123 更新时间:2023-12-02 02:14:16 25 4
gpt4 key购买 nike

在我的 Spring Cloud Task 项目中,我使用 Spring Batch。我想将元数据(BATCH_TASK_ 表)与生产数据分开,因此我配置了两个 DataSource,如下所示:

# DataSource: Production data
prod.datasource.jdbc-url=jdbc:sqlserver://localhost;databaseName=PROD
prod.datasource.data-source-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
prod.datasource.username=...
prod.datasource.password=...


# DataSource: Jobs and Tasks metadata
tasks.datasource.jdbc-url=jdbc:sqlserver://localhost;databaseName=TASKS
tasks.datasource.data-source-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
tasks.datasource.username=sa
tasks.datasource.password=...

+

public class DataSourceConfig {

@Bean
@Primary
@ConfigurationProperties(prefix = "prod.datasource")
public DataSource dataSourceProd() {
return DataSourceBuilder.create().build();
}


@Bean
@ConfigurationProperties(prefix = "tasks.datasource")
public DataSource dataSourceTasks() {
return DataSourceBuilder.create().build();
}

}

+

@Configuration
@EnableTask
@EnableBatchProcessing
@Import(DataSourceConfig.class)
public class JobConfig {

@Autowired
private JobBuilderFactory jobs;

@Autowired
private StepBuilderFactory steps;


@Bean
public TaskConfigurer taskConfigurer(@Qualifier("dataSourceTasks") DataSource source) {
return new DefaultTaskConfigurer(source);
}


@Bean
public BatchConfigurer batchConfigurer(@Qualifier("dataSourceTasks") DataSource source) {
return new DefaultBatchConfigurer(source);
}

//+jobs, steps...

当我运行它时,我得到 Cannot cast com.microsoft.sqlserver.jdbc.SQLServerDriver to javax.sql.DataSource from taskConfigurer bean。我错过了什么吗?

使用 Spring Boot starter Batch 2.0.0.RELEASE 和 Cloud starter Task 2.0.0.M3

最佳答案

使用prod.datasource.driverClassName

而不是

prod.datasource.data-source-class-name

关于java - 无法将 SQLServerDriver 转换为 DataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49514012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com