GCP扳手的数据源 [英] Data Source for GCP Spanner

查看:130
本文介绍了GCP扳手的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将为GCP扳手创建批处理,并计划使用需要数据源的JdbcCursorItemReader,因此我需要为我的GCP Spanner实例创建数据源,您能在这方面为我提供建议吗?

I am going to create batch for GCP spanner am planning to use JdbcCursorItemReader that needs datasource, So i need to create datasource for my GCP Spanner instance, Can you please suggest me on this?

推荐答案

您需要将Cloud Spanner JDBC驱动程序添加到您的构建路径中,如下所示:

You need to add the Cloud Spanner JDBC driver to your build path like this:

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-spanner-jdbc</artifactId>
      <version>1.9.0</version>
    </dependency>

然后,您可以按常规方式定义Spring数据源。以编程方式执行该操作应如下所示:

Then you can define a Spring data source in the normal way. Doing it programmatically would look like this:

    @Bean
    public DataSource spannerDataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.google.cloud.spanner.jdbc.JdbcDriver");
        dataSource.setUrl("jdbc:cloudspanner:/projects/<YOUR-PROJECT-ID>/instances/<YOUR-INSTANCE-ID>/databases/<YOUR-DATABASE-ID>?credentials=<PATH-TO-YOUR-SERVICE-CREDENTIALS>");
        return dataSource;
    }






- -评论后的其他信息----

Google Cloud Spanner不是Spring Batch默认支持的数据库。因此,您需要将数据库类型显式设置为支持的数据库类型之一。 看看这个答案查看操作方法。

Google Cloud Spanner is not a database that is supported by default by Spring Batch. You therefore need to explicitly set the database type to one of the supported database types. Have a look at this answer to see how that is done.

即使您正在使用另一个数据库,也需要选择一个受支持的数据库。这可能会导致其他兼容性问题,尤其是如果让Spring Batch自动生成数据模型时。如果您手动创建数据模型并且仅使用Spring Batch读取数据,那么应该不会有太大问题。我建议尝试将数据库类型设置为POSTGRES,看看是否可行。

You need to select one of the supported databases, even though you are using another database. This might cause other compatibility problems, especially if you let Spring Batch automatically generate your data model. If you create the data model by hand and only use Spring Batch for reading data, it should be less of a problem. I would recommend to try to set the database type to POSTGRES and see if it works.

这篇关于GCP扳手的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆