diff --git a/axon-cosmosdb-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/cosmosdb/springboot/autoconfig/CosmosAutoConfiguration.java b/axon-cosmosdb-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/cosmosdb/springboot/autoconfig/CosmosAutoConfiguration.java index f208ab1..c7afb43 100644 --- a/axon-cosmosdb-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/cosmosdb/springboot/autoconfig/CosmosAutoConfiguration.java +++ b/axon-cosmosdb-spring-boot-autoconfigure/src/main/java/org/axonframework/extensions/cosmosdb/springboot/autoconfig/CosmosAutoConfiguration.java @@ -6,12 +6,15 @@ import org.axonframework.serialization.Serializer; import org.axonframework.springboot.TokenStoreProperties; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; +import static java.util.Objects.isNull; + /** * Cosmos autoconfiguration class for Axon Framework application. Constructs the components which can be supplied by the * {@code axon-cosmosdb}. This is just the token store ({@link CosmosTokenStore}). @@ -33,15 +36,28 @@ public CosmosAutoConfiguration( this.tokenStoreProperties = tokenStoreProperties; } + @Value("${azure.cosmos.database:#{null}}") + private String dbName; + + @Value("${spring.cloud.azure.cosmos.database:#{null}}") + private String cloudDbName; + @Bean("tokenStore") @ConditionalOnMissingBean(TokenStore.class) public TokenStore tokenStore( @Qualifier(value = "azureCosmosAsyncClient") CosmosAsyncClient client, Serializer serializer ) { + String databaseName = "axon"; + if (!isNull(dbName)) { + databaseName = dbName; + } else if (!isNull(cloudDbName)) { + databaseName = cloudDbName; + } return CosmosTokenStore.builder() .client(client) .serializer(serializer) + .databaseName(databaseName) .claimTimeout(tokenStoreProperties.getClaimTimeout()) .build(); }