keeping Configuration in Separate class
This commit is contained in:
parent
8c0fc4830c
commit
9c846f0e84
|
@ -1,44 +1,12 @@
|
||||||
package com.baeldung.spring.data.cosmosdb;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCosmosRepositories(basePackageClasses = ProductRepository.class)
|
public class AzureCosmosDbApplication {
|
||||||
public class AzureCosmosDbApplication extends AbstractCosmosConfiguration {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(AzureCosmosDbApplication.class, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue