2

I have a spring boot application that will be communicating with two databases (Cassandra and DB2). I'll be using spring data in this application. Is it applicable to configure the data sources only in application.yml file, without writing java code. If so, how can I specify the dialect for each one?

Note: this application uses spring-data-cassandra for cassandra database and spring-data-jpa for db2 database.

For example:

spring:
  datasource:
    url: jdbc:db2://myRemoteHost:portNumber/MyDBName
    username: username
    password: password
    driver-class-name: com.ibm.db2.jcc.DB2Driver

  data:
    cassandra:
      cluster-name: cluster name
      keyspace-name: keyspace name
      port: myPortNumber
      contact-points: host1.com
      username: username
      password: password

Note: This question is different from Spring Boot Configure and Use Two DataSources . My question is to know if it's applicable to configure the data sources only in application.yml file without doing it manually, while the other question explains how to do it manually.

MoA
  • 458
  • 4
  • 20
  • 2
    @g00glen00b My question is different from [Spring Boot Configure and Use Two DataSources](https://stackoverflow.com/questions/30337582/spring-boot-configure-and-use-two-datasources). As I'm asking is it applicable or not while the other question explaining how to do it manually. However, after I tried it on two different types of spring data, it worked. As in my case I mentioned that I'm using spring data jpa and spring data cassandra. – MoA Jan 25 '19 at 01:16

1 Answers1

2

I found that it's applicable for the case above, as the application uses spring-data-cassandra for cassandra database and spring-data-jpa for connecting to db2 database.

Spring boot is smart enough to figure out which repositories and entities are used by spring-data-jpa and which are used by spring-data-cassandra.

As long as you are using a different spring data type for each database, it' applicable.

MoA
  • 458
  • 4
  • 20