microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
93 stars 68 forks source link

Not able to connect with 2 Cosmos DB with single application #543

Closed bajrangprasad01 closed 3 years ago

bajrangprasad01 commented 4 years ago

I have tried to connect with 2 datasource of cosmos but not able to connect. I have tried all the solution given but not a single thing is working.

@configuration
@EnableCosmosRepositories(basePackages = "com.bajrang.repositories.kooprepositories")
public class KoopCosmosConfig extends AbstractCosmosConfiguration {
@value("${spring.koop.azure.cosmosdb.uri}")
private String uri;
@value("${spring.koop.azure.cosmosdb.key}")
private String key;
@value("${spring.koop.azure.cosmosdb.database}")
private String database;

@Bean
@Primary
public CosmosDBConfig koopCosmosDBConfig() {
    CosmosDBConfig cosmosDBConfig = CosmosDBConfig.builder(uri, key, database).build();
    return cosmosDBConfig;
}

===================================

@configuration
@EnableTransactionManagement
@EnableCosmosRepositories(basePackages = "com.bajrang.repositories.galactusrepositories")
public class GalactusCosmosConfig extends AbstractCosmosConfiguration {
@value("${spring.galactus.azure.cosmosdb.uri}")
private String uri;
@value("${spring.galactus.azure.cosmosdb.key}")
private String key;
@value("${spring.galactus.azure.cosmosdb.database}")
private String database;

@Bean
public CosmosDBConfig galactusCosmosDBConfig() {
    CosmosDBConfig cosmosDBConfig = CosmosDBConfig.builder(uri, key, database).build();
    return cosmosDBConfig;
}

This error is comes

Parameter 0 of method cosmosTemplate in com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration required a single bean, but 2 were found:
- galactusCosmosDBConfig: defined by method 'galactusCosmosDBConfig' in class path resource [com/bajrang/configs/GalactusCosmosConfig.class]
- koopCosmosDBConfig: defined by method 'koopCosmosDBConfig' in class path resource [com/bajrang/configs/KoopCosmosConfig.class]

Action:

Consider marking one of the beans as @primary, updating the consumer to accept multiple beans, or using @qualifier to identify the bean that should be consumed

Process finished with exit code 1

I have tried with this configuration but not able to connect with two data source.

Please help me I urgently need to do this but I am not able to do. I need to connect with 2 databases but it is not happening.

kushagraThapar commented 4 years ago

@bajrangprasad01 - this is a feature request and is being tracked here : https://github.com/microsoft/spring-data-cosmosdb/issues/520

kushagraThapar commented 3 years ago

@bajrangprasad01 - I am closing the issue here, since this is being now tracked here : https://github.com/Azure/azure-sdk-for-java/issues/12713

We have migrated the repo to here: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/cosmos/azure-spring-data-cosmosdb

Future development will happen in the new repo.