From 9c846f0e842799543be23dc71b0c54bbb697b474 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 15 Aug 2020 03:21:29 +0530 Subject: [PATCH] keeping Configuration in Separate class --- .../cosmosdb/AzureCosmosDbApplication.java | 34 +---------------- .../config/AzureCosmosDbConfiguration.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java index 7a91cd7d33..5a1764adc6 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java @@ -1,44 +1,12 @@ package com.baeldung.spring.data.cosmosdb; -import com.azure.data.cosmos.CosmosKeyCredential; -import com.baeldung.spring.data.cosmosdb.repository.ProductRepository; -import com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration; -import com.microsoft.azure.spring.data.cosmosdb.config.CosmosDBConfig; -import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories; - -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; @SpringBootApplication -@EnableCosmosRepositories(basePackageClasses = ProductRepository.class) -public class AzureCosmosDbApplication extends AbstractCosmosConfiguration { +public class AzureCosmosDbApplication { public static void main(String[] args) { SpringApplication.run(AzureCosmosDbApplication.class, args); } - - @Value("${azure.cosmosdb.uri}") - private String uri; - - @Value("${azure.cosmosdb.key}") - private String key; - - @Value("${azure.cosmosdb.secondaryKey}") - private String secondaryKey; - - @Value("${azure.cosmosdb.database}") - private String dbName; - - private CosmosKeyCredential cosmosKeyCredential; - - @Bean - public CosmosDBConfig getConfig() { - this.cosmosKeyCredential = new CosmosKeyCredential(key); - CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName) - .build(); - return cosmosdbConfig; - } - } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java new file mode 100644 index 0000000000..7d3322faf6 --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java @@ -0,0 +1,37 @@ +package com.baeldung.spring.data.cosmosdb.config; + +import com.azure.data.cosmos.CosmosKeyCredential; +import com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration; +import com.microsoft.azure.spring.data.cosmosdb.config.CosmosDBConfig; +import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableCosmosRepositories(basePackages = "com.baeldung.spring.data.cosmosdb.repository") +public class AzureCosmosDbConfiguration extends AbstractCosmosConfiguration { + + @Value("${azure.cosmosdb.uri}") + private String uri; + + @Value("${azure.cosmosdb.key}") + private String key; + + @Value("${azure.cosmosdb.secondaryKey}") + private String secondaryKey; + + @Value("${azure.cosmosdb.database}") + private String dbName; + + private CosmosKeyCredential cosmosKeyCredential; + + @Bean + public CosmosDBConfig getConfig() { + this.cosmosKeyCredential = new CosmosKeyCredential(key); + CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName) + .build(); + return cosmosdbConfig; + } +}