Requires DocumentDBConfig be provided as bean (#357)
This commit is contained in:
Родитель
a34f2cca20
Коммит
60f9c38739
|
@ -19,11 +19,9 @@ import org.springframework.context.annotation.Configuration;
|
|||
|
||||
@Configuration
|
||||
public abstract class AbstractDocumentDbConfiguration extends DocumentDbConfigurationSupport {
|
||||
public abstract DocumentDBConfig getConfig();
|
||||
|
||||
@Bean
|
||||
public DocumentClient documentClient() {
|
||||
return this.documentDbFactory().getDocumentClient();
|
||||
public DocumentClient documentClient(DocumentDBConfig config) {
|
||||
return this.documentDbFactory(config).getDocumentClient();
|
||||
}
|
||||
|
||||
@Qualifier(Constants.OBJECTMAPPER_BEAN_NAME)
|
||||
|
@ -31,14 +29,13 @@ public abstract class AbstractDocumentDbConfiguration extends DocumentDbConfigur
|
|||
private ObjectMapper objectMapper;
|
||||
|
||||
@Bean
|
||||
public DocumentDbFactory documentDbFactory() {
|
||||
return new DocumentDbFactory(this.getConfig());
|
||||
public DocumentDbFactory documentDbFactory(DocumentDBConfig config) {
|
||||
return new DocumentDbFactory(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DocumentDbTemplate documentDbTemplate() throws ClassNotFoundException {
|
||||
final DocumentDBConfig config = getConfig();
|
||||
return new DocumentDbTemplate(this.documentDbFactory(), this.mappingDocumentDbConverter(),
|
||||
public DocumentDbTemplate documentDbTemplate(DocumentDBConfig config) throws ClassNotFoundException {
|
||||
return new DocumentDbTemplate(this.documentDbFactory(config), this.mappingDocumentDbConverter(),
|
||||
config.getDatabase());
|
||||
}
|
||||
|
||||
|
|
|
@ -76,13 +76,13 @@ public class AbstractDocumentDbConfigurationUnitTest {
|
|||
@Mock
|
||||
private DocumentClient mockClient;
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public DocumentDBConfig getConfig() {
|
||||
return DocumentDBConfig.builder("http://fake-uri", "fake-key", TestConstants.DB_NAME).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentClient documentClient() {
|
||||
public DocumentClient documentClient(DocumentDBConfig config) {
|
||||
return mockClient;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class AbstractDocumentDbConfigurationUnitTest {
|
|||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public DocumentDBConfig getConfig() {
|
||||
final RequestOptions options = getRequestOptions();
|
||||
return DocumentDBConfig.builder("http://fake-uri", "fake-key", TestConstants.DB_NAME)
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.microsoft.azure.spring.data.cosmosdb.config.DocumentDBConfig;
|
|||
import com.microsoft.azure.spring.data.cosmosdb.performance.utils.Constants;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableDocumentDbRepositories;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
|
@ -23,7 +24,7 @@ public class PerfConfiguration extends AbstractDocumentDbConfiguration {
|
|||
@Value("${cosmosdb.key:}")
|
||||
private String documentDbKey;
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public DocumentDBConfig getConfig() {
|
||||
return DocumentDBConfig.builder(documentDbUri, documentDbKey, Constants.PERF_DATABASE_NAME).build();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.microsoft.azure.spring.data.cosmosdb.config.AbstractDocumentDbConfigu
|
|||
import com.microsoft.azure.spring.data.cosmosdb.config.DocumentDBConfig;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableDocumentDbRepositories;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
@ -42,7 +43,7 @@ public class TestRepositoryConfig extends AbstractDocumentDbConfiguration {
|
|||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public DocumentDBConfig getConfig() {
|
||||
final String dbName = StringUtils.hasText(this.database) ? this.database : TestConstants.DB_NAME;
|
||||
final RequestOptions options = getRequestOptions();
|
||||
|
|
Загрузка…
Ссылка в новой задаче