Release/2.2.0.M1 (#724)
* update version to 2.2.0.M1 * upgrade dependencies * update spring.security.oauth2.client.registration. redirect-uri-template to redirect-uri * change documentdb to cosmodb and fix spring security issues * move reactor-netty to parent pom and fix gradle * code quality * revert
This commit is contained in:
Родитель
23127f88db
Коммит
7f90210e27
|
@ -7,7 +7,7 @@ Also test if the latest release.
|
|||
- Spring boot starter:
|
||||
<!--Which Spring boot starters have the issue, pick items below and delete the rest-->
|
||||
- active directory spring boot starter
|
||||
- documentdb spring boot starter
|
||||
- cosmosdb spring boot starter
|
||||
- key vault spring boot starter
|
||||
- media services spring boot starter
|
||||
- service bus spring boot starter
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
## Starter Names
|
||||
<!--Which Spring boot starters the change involves, pick items below and delete the rest-->
|
||||
- active directory spring boot starter
|
||||
- documentdb spring boot starter
|
||||
- cosmosdb spring boot starter
|
||||
- key vault spring boot starter
|
||||
- media services spring boot starter
|
||||
- service bus spring boot starter
|
||||
|
|
|
@ -61,7 +61,7 @@ Please follow [instructions here](./HowToContribute.md) to build from source or
|
|||
### Other articles
|
||||
You could check below articles to learn more on usage of specific starters.
|
||||
|
||||
[How to use the Spring Boot Starter with Azure Cosmos DB DocumentDB API](https://docs.microsoft.com/en-us/azure/cosmos-db/documentdb-java-spring-boot-starter-with-cosmos-db)
|
||||
[How to use the Spring Boot Starter with Azure Cosmos DB API](https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-cosmos-db)
|
||||
|
||||
### Filing Issues
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-bom</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Azure Spring Boot BOM</name>
|
||||
|
@ -46,10 +46,10 @@
|
|||
</scm>
|
||||
|
||||
<properties>
|
||||
<azure.spring.boot.version>2.1.8-SNAPSHOT</azure.spring.boot.version>
|
||||
<azure.dependencies.bom.version>2.1.0.M6</azure.dependencies.bom.version>
|
||||
<spring.data.cosmosdb.version>2.1.7</spring.data.cosmosdb.version>
|
||||
<spring.data.gremlin.version>2.1.7</spring.data.gremlin.version>
|
||||
<azure.spring.boot.version>2.2.0.M1</azure.spring.boot.version>
|
||||
<azure.dependencies.bom.version>2.2.0.M1</azure.dependencies.bom.version>
|
||||
<spring.data.cosmosdb.version>2.2.0.M1</spring.data.cosmosdb.version>
|
||||
<spring.data.gremlin.version>2.2.0.M1</spring.data.gremlin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -138,14 +138,14 @@
|
|||
<artifactId>azure-spring-boot</artifactId>
|
||||
<version>${azure.spring.boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Azure Client Authentication -->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-client-authentication</artifactId>
|
||||
<version>1.6.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestone</id>
|
||||
<name>Spring Portfolio Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-bom</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../azure-spring-boot-bom/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -27,21 +27,21 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<spring.boot.version>2.1.7.RELEASE</spring.boot.version>
|
||||
<spring.boot.version>2.2.0.M6</spring.boot.version>
|
||||
<spring.springframework.version>5.2.0.RC2</spring.springframework.version>
|
||||
<findbugs.annotations.version>2.0.1</findbugs.annotations.version>
|
||||
<nimbus.jose.jwt.version>4.39.2</nimbus.jose.jwt.version>
|
||||
<mockito.core.version>2.8.9</mockito.core.version>
|
||||
<azuremonitor.micrometer.registry.version>1.1.0</azuremonitor.micrometer.registry.version>
|
||||
<micrometer.core.version>1.1.0</micrometer.core.version>
|
||||
<spring-boot-actuator-autoconfigure.version>2.1.7.RELEASE</spring-boot-actuator-autoconfigure.version>
|
||||
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
|
||||
<wiremock-standalone.version>2.19.0</wiremock-standalone.version>
|
||||
<commons-io.version>2.3</commons-io.version>
|
||||
<hibernate.validator.version>6.0.9.Final</hibernate.validator.version>
|
||||
<javax.jms-api.version>2.0.1</javax.jms-api.version>
|
||||
<spring-jms.version>5.1.9.RELEASE</spring-jms.version>
|
||||
<qpid-jms-client.version>0.43.0</qpid-jms-client.version>
|
||||
<junit-params.version>1.1.1</junit-params.version>
|
||||
<reactor-netty.version>0.8.3.RELEASE</reactor-netty.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
@ -103,32 +103,11 @@
|
|||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>${powermock.api.mockito2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-registry-azure-monitor</artifactId>
|
||||
<version>${azuremonitor.micrometer.registry.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<version>${micrometer.core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
||||
<version>${spring-boot-actuator-autoconfigure.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock-standalone</artifactId>
|
||||
|
@ -144,7 +123,7 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jms</artifactId>
|
||||
<version>${spring-jms.version}</version>
|
||||
<version>${spring.springframework.version}</version>
|
||||
</dependency>
|
||||
<!--Qpid-->
|
||||
<dependency>
|
||||
|
@ -159,6 +138,12 @@
|
|||
<artifactId>JUnitParams</artifactId>
|
||||
<version>${junit-params.version}</version>
|
||||
</dependency>
|
||||
<!-- the version include from Spring-Boot is not compatible with which Cosmos SDK depends on -->
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.netty</groupId>
|
||||
<artifactId>reactor-netty</artifactId>
|
||||
<version>${reactor-netty.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ If installed, you should see something like this:
|
|||
```
|
||||
service plans description
|
||||
azure-cosmosdb standard* Azure CosmosDb Service
|
||||
azure-documentdb standard* Azure DocumentDb Service
|
||||
azure-mysqldb basic50*, basic100*, standard100*, standard200*, standard400*,
|
||||
standard800* Azure Database for MySQL Service
|
||||
azure-postgresqldb basic50*, basic100*, standard100*, standard200*, standard400*,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
package sample.cloudfoundry.documentdb;
|
||||
package sample.cloudfoundry.cosmosdb;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -18,10 +18,10 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
public class DocumentDbRestController {
|
||||
public class CosmosDbRestController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(DocumentDbRestController.class);
|
||||
.getLogger(CosmosDbRestController.class);
|
||||
|
||||
private static final String CR = "</BR>";
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* license information.
|
||||
*/
|
||||
|
||||
package sample.cloudfoundry.documentdb;
|
||||
package sample.cloudfoundry.cosmosdb;
|
||||
|
||||
public class User {
|
||||
private String id;
|
|
@ -4,11 +4,11 @@
|
|||
* license information.
|
||||
*/
|
||||
|
||||
package sample.documentdb;
|
||||
package sample.cloudfoundry.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.CosmosRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends DocumentDbRepository<User, String> {
|
||||
public interface UserRepository extends CosmosRepository<User, String> {
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package sample.cloudfoundry.documentdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends DocumentDbRepository<User, String> {
|
||||
}
|
|
@ -48,7 +48,7 @@ This sample project demonstrates how to use Azure CosmosDB via Spring Boot Start
|
|||
|
||||
### Known issue
|
||||
|
||||
Directly running the sample app from IDE IntelliJ or Eclipse has below security exception if using the *released* starter. The root cause is that the release `spring-data-azure-documentdb` jar is code-signed by us. We're working actively to resolve this issue.
|
||||
Directly running the sample app from IDE IntelliJ or Eclipse has below security exception if using the *released* starter. The root cause is that the release `spring-data-azure-cosmosdb` jar is code-signed by us. We're working actively to resolve this issue.
|
||||
|
||||
```
|
||||
Caused by: java.lang.SecurityException: class "com.microsoft.azure.sample.User_Accessor_yhb3bq"'s signer information does not match signer information of other classes in the same package
|
||||
|
@ -61,5 +61,5 @@ If `com.fasterxml.jackson.databind.JsonMappingException` is thrown during deseri
|
|||
|
||||
### More details
|
||||
|
||||
Please refer to [this article](https://docs.microsoft.com/en-us/azure/cosmos-db/documentdb-java-spring-boot-starter-with-cosmos-db) for the tutorial about how to use the Spring Boot Starter with Azure Cosmos DB DocumentDB API.
|
||||
Please refer to [this article](https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-cosmos-db) for the tutorial about how to use the Spring Boot Starter with Azure Cosmos DB API.
|
||||
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.netty</groupId>
|
||||
<artifactId>reactor-netty</artifactId>
|
||||
<version>0.8.3.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
package sample.cosmosdb;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.util.Assert;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Optional;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CosmosSampleApplication implements CommandLineRunner {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosSampleApplication.class);
|
||||
|
||||
@Autowired
|
||||
private UserRepository repository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CosmosSampleApplication.class, args);
|
||||
}
|
||||
|
||||
public void run(String... var1) throws Exception {
|
||||
final User testUser = new User("testId", "testFirstName", "testLastName", "test address line one");
|
||||
|
||||
// Save the User class to Azure CosmosDB database.
|
||||
final Mono<User> saveUserMono = repository.save(testUser);
|
||||
|
||||
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
|
||||
|
||||
// Nothing happens until we subscribe to these Monos.
|
||||
// findById will not return the user as user is not present.
|
||||
final Mono<User> findByIdMono = repository.findById(testUser.getId());
|
||||
final User findByIdUser = findByIdMono.block();
|
||||
Assert.isNull(findByIdUser, "User must be null");
|
||||
|
||||
final User savedUser = saveUserMono.block();
|
||||
Assert.state(savedUser != null, "Saved user must not be null");
|
||||
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()), "Saved user first name doesn't match");
|
||||
|
||||
firstNameUserFlux.collectList().block();
|
||||
|
||||
final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional();
|
||||
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user.");
|
||||
|
||||
final User result = optionalUserResult.get();
|
||||
Assert.state(result.getFirstName().equals(testUser.getFirstName()), "query result firstName doesn't match!");
|
||||
Assert.state(result.getLastName().equals(testUser.getLastName()), "query result lastName doesn't match!");
|
||||
|
||||
LOGGER.info("findOne in User collection get result: {}", result.toString());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void setup() {
|
||||
// For this example, remove all of the existing records.
|
||||
this.repository.deleteAll().block();
|
||||
}
|
||||
}
|
|
@ -4,25 +4,29 @@
|
|||
* license information.
|
||||
*/
|
||||
|
||||
package sample.documentdb;
|
||||
package sample.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
@Document(collection = "mycollection")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
@Id
|
||||
private String id;
|
||||
private String firstName;
|
||||
@PartitionKey
|
||||
private String lastName;
|
||||
private String address;
|
||||
|
||||
public User() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s, %s", firstName, lastName, address);
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package sample.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.ReactiveCosmosRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends ReactiveCosmosRepository<User, String> {
|
||||
|
||||
Flux<User> findByFirstName(String firstName);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
package sample.documentdb;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DocumentDbSampleApplication implements CommandLineRunner {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DocumentDbSampleApplication.class);
|
||||
|
||||
@Autowired
|
||||
private UserRepository repository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DocumentDbSampleApplication.class, args);
|
||||
}
|
||||
|
||||
public void run(String... var1) throws Exception {
|
||||
final User testUser = new User("testId", "testFirstName", "testLastName", "test address line one");
|
||||
|
||||
repository.deleteAll();
|
||||
repository.save(testUser);
|
||||
|
||||
final Optional<User> opResult = repository.findById(testUser.getId());
|
||||
Assert.isTrue(opResult.isPresent(), "Cannot find user.");
|
||||
|
||||
final User result = opResult.get();
|
||||
Assert.state(result.getFirstName().equals(testUser.getFirstName()), "query result firstName doesn't match!");
|
||||
Assert.state(result.getLastName().equals(testUser.getLastName()), "query result lastName doesn't match!");
|
||||
|
||||
LOGGER.info("findOne in User collection get result: {}", result.toString());
|
||||
}
|
||||
}
|
|
@ -38,7 +38,6 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||
<version>2.1.7.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||
<version>2.1.7.RELEASE</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
buildscript {
|
||||
ext {
|
||||
springBootVersion = '2.1.7.RELEASE'
|
||||
springBootVersion = '2.2.0.M6'
|
||||
}
|
||||
repositories {
|
||||
maven { url "http://repo.spring.io/libs-milestone" }
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
|
@ -18,7 +19,7 @@ allprojects {
|
|||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
ext {
|
||||
azureSpringBootStartersVersion = '2.1.8-SNAPSHOT'
|
||||
azureSpringBootStartersVersion = '2.2.0.M1'
|
||||
commonsioVersion = '2.3'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.7.RELEASE</version>
|
||||
<version>2.2.0.M6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
@ -66,7 +66,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-bom</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -75,6 +75,7 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -157,4 +158,19 @@
|
|||
<module>azure-servicebus-jms-queue-spring-boot-sample</module>
|
||||
<module>azure-servicebus-jms-topic-spring-boot-sample</module>
|
||||
</modules>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestone</id>
|
||||
<name>Spring Portfolio Milestone Repository</name>
|
||||
<url>http://maven.springframework.org/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>azure-active-directory-b2c-spring-boot-starter</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
|
||||
<name>Azure AD B2C Spring Security Integration Spring Boot Starter</name>
|
||||
<description>Spring Boot Starter for Azure AD B2C and Spring Security Integration</description>
|
||||
|
@ -36,7 +36,6 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- Below poms will be replaced to azure-spring-boot-starter pom when no milestone tag. -->
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* [Quick Start](#quick-start)
|
||||
|
||||
## Feature List
|
||||
- Spring Data CRUDRepository basic CRUD functionality
|
||||
- Spring Data ReactiveCrudRepository basic CRUD functionality
|
||||
- save
|
||||
- findAll
|
||||
- findOne by Id
|
||||
|
@ -42,7 +42,7 @@ If you are using Maven, add the following dependency.
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
|
||||
<version>2.1.6</version>
|
||||
<version>2.2.0.M6</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
@ -51,37 +51,37 @@ If you are using Maven, add the following dependency.
|
|||
Open `application.properties` file and add below properties with your Cosmos DB credentials.
|
||||
|
||||
```
|
||||
azure.cosmosdb.uri=your-documentdb-uri
|
||||
azure.cosmosdb.key=your-documentdb-key
|
||||
azure.cosmosdb.database=your-documentdb-databasename
|
||||
azure.cosmosdb.uri=your-cosmosdb-uri
|
||||
azure.cosmosdb.key=your-cosmosdb-key
|
||||
azure.cosmosdb.database=your-cosmosdb-databasename
|
||||
```
|
||||
|
||||
Property `azure.cosmosdb.consistency-level` is also supported.
|
||||
|
||||
Property `azure.cosmosdb.cosmosKeyCredential` is also supported. CosmosKeyCredential feature provides capability to
|
||||
rotate keys on the fly. You can switch keys using switchToSecondaryKey(). For more information on this, see the Sample
|
||||
Application code.
|
||||
|
||||
### Define an entity
|
||||
Define a simple entity as Document in Cosmos DB.
|
||||
|
||||
```
|
||||
@Document(collection = "mycollection")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class User {
|
||||
@Id
|
||||
private String id;
|
||||
private String firstName;
|
||||
@PartitionKey
|
||||
private String lastName;
|
||||
// if emailAddress is mapped to id, then
|
||||
// @Id
|
||||
// private String emailAddress
|
||||
|
||||
... // setters and getters
|
||||
|
||||
public User(String id, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
private String address;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("User: %s %s, %s", firstName, lastName);
|
||||
return String.format("User: %s %s, %s", firstName, lastName, address);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -90,43 +90,72 @@ public class User {
|
|||
Annotation `@Document(collection="mycollection")` is used to specify the collection name of your document in Azure Cosmos DB.
|
||||
|
||||
### Create repositories
|
||||
Extends DocumentDbRepository interface, which provides Spring Data repository support.
|
||||
Extends ReactiveCosmosRepository interface, which provides Spring Data repository support.
|
||||
|
||||
```
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.ReactiveCosmosRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends DocumentDbRepository<User, String> {
|
||||
public interface UserRepository extends ReactiveCosmosRepository<User, String> {
|
||||
|
||||
Flux<User> findByFirstName(String firstName);
|
||||
}
|
||||
```
|
||||
|
||||
So far DocumentDbRepository provides basic save, delete and find operations. More operations will be supported later.
|
||||
So far ReactiveCosmosRepository provides basic save, delete and find operations. More operations will be supported later.
|
||||
|
||||
### Create an Application class
|
||||
Here create an application class with all the components
|
||||
```
|
||||
@SpringBootApplication
|
||||
public class SampleApplication implements CommandLineRunner {
|
||||
public class CosmosSampleApplication implements CommandLineRunner {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CosmosSampleApplication.class);
|
||||
|
||||
@Autowired
|
||||
private UserRepository repository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
SpringApplication.run(CosmosSampleApplication.class, args);
|
||||
}
|
||||
|
||||
public void run(String... var1) throws Exception {
|
||||
final User testUser = new User("testId", "testFirstName", "testLastName", "test address line one");
|
||||
|
||||
final User testUser = new User("testId", "testFirstName", "testLastName");
|
||||
// Save the User class to Azure CosmosDB database.
|
||||
final Mono<User> saveUserMono = repository.save(testUser);
|
||||
|
||||
repository.deleteAll();
|
||||
repository.save(testUser);
|
||||
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
|
||||
|
||||
final User result = repository.findOne(testUser.getId());
|
||||
// if emailAddress is mapped to id, then
|
||||
// final User result = respository.findOne(testUser.getEmailAddress());
|
||||
// Nothing happens until we subscribe to these Monos.
|
||||
// findById will not return the user as user is not present.
|
||||
final Mono<User> findByIdMono = repository.findById(testUser.getId());
|
||||
final User findByIdUser = findByIdMono.block();
|
||||
Assert.isNull(findByIdUser, "User must be null");
|
||||
|
||||
final User savedUser = saveUserMono.block();
|
||||
Assert.state(savedUser != null, "Saved user must not be null");
|
||||
Assert.state(savedUser.getFirstName().equals(testUser.getFirstName()), "Saved user first name doesn't match");
|
||||
|
||||
final List<User> users = firstNameUserFlux.collectList().block();
|
||||
|
||||
final Optional<User> optionalUserResult = repository.findById(testUser.getId()).blockOptional();
|
||||
Assert.isTrue(optionalUserResult.isPresent(), "Cannot find user.");
|
||||
|
||||
final User result = optionalUserResult.get();
|
||||
Assert.state(result.getFirstName().equals(testUser.getFirstName()), "query result firstName doesn't match!");
|
||||
Assert.state(result.getLastName().equals(testUser.getLastName()), "query result lastName doesn't match!");
|
||||
|
||||
LOGGER.info("findOne in User collection get result: {}", result.toString());
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void setup() {
|
||||
// For this example, remove all of the existing records.
|
||||
this.repository.deleteAll().block();
|
||||
}
|
||||
}
|
||||
```
|
||||
Autowired UserRepository interface, then can do save, delete and find operations.
|
||||
|
@ -140,6 +169,6 @@ Find more information about Azure Service Privacy Statement, please check [Micro
|
|||
|
||||
### Further info
|
||||
|
||||
Besides using this Azure DocumentDB Spring Boot Starter, you can directly use Spring Data for Azure DocumentDB package for more complex scenarios. Please refer to [Spring Data for Azure DocumentDB](https://github.com/Microsoft/spring-data-documentdb) for more details.
|
||||
Besides using this Azure CosmosDb Spring Boot Starter, you can directly use Spring Data for Azure CosmosDb package for more complex scenarios. Please refer to [Spring Data for Azure CosmosDB](https://github.com/Microsoft/spring-data-cosmosdb) for more details.
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -30,6 +30,10 @@
|
|||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>spring-data-cosmosdb</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.netty</groupId>
|
||||
<artifactId>reactor-netty</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -9,7 +9,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ public class Network {
|
|||
```
|
||||
|
||||
### Create repositories
|
||||
Extends DocumentDbRepository interface, which provides Spring Data repository support.
|
||||
Extends CosmosRepository interface, which provides Spring Data repository support.
|
||||
|
||||
```
|
||||
import GremlinRepository;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-parent</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<relativePath>../azure-spring-boot-parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -133,7 +133,7 @@
|
|||
<!-- Azure libraries-->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-documentdb</artifactId>
|
||||
<artifactId>azure-cosmos</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -199,12 +199,6 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Annotation processor -->
|
||||
|
@ -266,6 +260,5 @@
|
|||
<artifactId>qpid-jms-client</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.documentdb.ConnectionPolicy;
|
||||
import com.microsoft.azure.documentdb.DocumentClient;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.config.AbstractDocumentDbConfiguration;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.config.DocumentDBConfig;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbTemplate;
|
||||
import com.azure.data.cosmos.ConnectionPolicy;
|
||||
import com.azure.data.cosmos.CosmosClient;
|
||||
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.core.CosmosTemplate;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
@ -18,22 +18,22 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({DocumentClient.class, DocumentDbTemplate.class})
|
||||
@EnableConfigurationProperties(DocumentDBProperties.class)
|
||||
public class DocumentDBAutoConfiguration extends AbstractDocumentDbConfiguration {
|
||||
private final DocumentDBProperties properties;
|
||||
@ConditionalOnClass({ CosmosClient.class, CosmosTemplate.class })
|
||||
@EnableConfigurationProperties(CosmosDBProperties.class)
|
||||
public class CosmosAutoConfiguration extends AbstractCosmosConfiguration {
|
||||
private final CosmosDBProperties properties;
|
||||
private final ConnectionPolicy policy;
|
||||
|
||||
public DocumentDBAutoConfiguration(DocumentDBProperties properties,
|
||||
ObjectProvider<ConnectionPolicy> connectionPolicyObjectProvider) {
|
||||
public CosmosAutoConfiguration(CosmosDBProperties properties,
|
||||
ObjectProvider<ConnectionPolicy> connectionPolicyObjectProvider) {
|
||||
this.properties = properties;
|
||||
this.policy = connectionPolicyObjectProvider.getIfAvailable();
|
||||
configConnectionPolicy(properties, policy);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DocumentDBConfig documentDbConfig() {
|
||||
final DocumentDBConfig config = DocumentDBConfig.builder(
|
||||
public CosmosDBConfig cosmosDBConfig() {
|
||||
final CosmosDBConfig config = CosmosDBConfig.builder(
|
||||
properties.getUri(), properties.getKey(), properties.getDatabase())
|
||||
.consistencyLevel(properties.getConsistencyLevel())
|
||||
.allowTelemetry(properties.isAllowTelemetry())
|
||||
|
@ -43,9 +43,9 @@ public class DocumentDBAutoConfiguration extends AbstractDocumentDbConfiguration
|
|||
return config;
|
||||
}
|
||||
|
||||
private void configConnectionPolicy(DocumentDBProperties properties, ConnectionPolicy connectionPolicy) {
|
||||
// This is a temp fix as DocumentDbFactory does not support loading ConnectionPolicy bean from context
|
||||
final ConnectionPolicy policy = connectionPolicy == null ? ConnectionPolicy.GetDefault() : connectionPolicy;
|
||||
private void configConnectionPolicy(CosmosDBProperties properties, ConnectionPolicy connectionPolicy) {
|
||||
// This is a temp fix as CosmosDbFactory does not support loading ConnectionPolicy bean from context
|
||||
final ConnectionPolicy policy = connectionPolicy == null ? ConnectionPolicy.defaultPolicy() : connectionPolicy;
|
||||
|
||||
properties.setConnectionPolicy(policy);
|
||||
}
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.documentdb.ConnectionPolicy;
|
||||
import com.microsoft.azure.documentdb.ConsistencyLevel;
|
||||
import com.azure.data.cosmos.ConnectionPolicy;
|
||||
import com.azure.data.cosmos.ConsistencyLevel;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
|
||||
@Validated
|
||||
@ConfigurationProperties("azure.cosmosdb")
|
||||
public class DocumentDBProperties {
|
||||
public class CosmosDBProperties {
|
||||
/**
|
||||
* Document DB URI.
|
||||
*/
|
||||
|
@ -45,7 +45,7 @@ public class DocumentDBProperties {
|
|||
*/
|
||||
private boolean allowTelemetry = true;
|
||||
|
||||
private ConnectionPolicy connectionPolicy = ConnectionPolicy.GetDefault();
|
||||
private ConnectionPolicy connectionPolicy = ConnectionPolicy.defaultPolicy();
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.ReactiveCosmosRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.ReactiveCosmosRepositoryConfigurationExtension;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.support.ReactiveCosmosRepositoryFactoryBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ ReactiveCosmosRepository.class })
|
||||
@ConditionalOnMissingBean({ ReactiveCosmosRepositoryFactoryBean.class,
|
||||
ReactiveCosmosRepositoryConfigurationExtension.class })
|
||||
@ConditionalOnProperty(prefix = "azure.cosmosdb.repositories",
|
||||
name = "enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@Import(CosmosDbReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||
public class CosmosDbReactiveRepositoriesAutoConfiguration {
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableReactiveCosmosRepositories;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.ReactiveCosmosRepositoryConfigurationExtension;
|
||||
import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class CosmosDbReactiveRepositoriesAutoConfigureRegistrar extends AbstractRepositoryConfigurationSourceSupport {
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
return EnableReactiveCosmosRepositories.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getConfiguration() {
|
||||
return EnableCosmosDbReactiveRepositoriesConfiguration.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
|
||||
return new ReactiveCosmosRepositoryConfigurationExtension();
|
||||
}
|
||||
|
||||
@EnableReactiveCosmosRepositories
|
||||
private static class EnableCosmosDbReactiveRepositoriesConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.DocumentDbRepositoryConfigurationExtension;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.support.DocumentDbRepositoryFactoryBean;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.CosmosRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.CosmosRepositoryConfigurationExtension;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.support.CosmosRepositoryFactoryBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
@ -17,12 +17,13 @@ import org.springframework.context.annotation.Import;
|
|||
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({DocumentDbRepository.class})
|
||||
@ConditionalOnMissingBean({DocumentDbRepositoryFactoryBean.class, DocumentDbRepositoryConfigurationExtension.class})
|
||||
@ConditionalOnClass({ CosmosRepository.class })
|
||||
@ConditionalOnMissingBean({ CosmosRepositoryFactoryBean.class,
|
||||
CosmosRepositoryConfigurationExtension.class })
|
||||
@ConditionalOnProperty(prefix = "azure.cosmosdb.repositories",
|
||||
name = "enabled",
|
||||
havingValue = "true",
|
||||
matchIfMissing = true)
|
||||
@Import(DocumentDbRepositoriesAutoConfigureRegistrar.class)
|
||||
public class DocumentDbRepositoriesAutoConfiguration {
|
||||
@Import(CosmosDbRepositoriesAutoConfigureRegistrar.class)
|
||||
public class CosmosDbRepositoriesAutoConfiguration {
|
||||
}
|
|
@ -6,31 +6,31 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.DocumentDbRepositoryConfigurationExtension;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableDocumentDbRepositories;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.CosmosRepositoryConfigurationExtension;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories;
|
||||
import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
|
||||
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class DocumentDbRepositoriesAutoConfigureRegistrar extends AbstractRepositoryConfigurationSourceSupport {
|
||||
public class CosmosDbRepositoriesAutoConfigureRegistrar extends AbstractRepositoryConfigurationSourceSupport {
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotation() {
|
||||
return EnableDocumentDbRepositories.class;
|
||||
return EnableCosmosRepositories.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getConfiguration() {
|
||||
return EnableDocumentDbRepositoriesConfiguration.class;
|
||||
return EnableCosmosDbRepositoriesConfiguration.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
|
||||
return new DocumentDbRepositoryConfigurationExtension();
|
||||
return new CosmosRepositoryConfigurationExtension();
|
||||
}
|
||||
|
||||
@EnableDocumentDbRepositories
|
||||
private static class EnableDocumentDbRepositoriesConfiguration {
|
||||
@EnableCosmosRepositories
|
||||
private static class EnableCosmosDbRepositoriesConfiguration {
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
org.springframework.boot.env.EnvironmentPostProcessor=com.microsoft.azure.spring.cloudfoundry.environment.VcapProcessor,\
|
||||
com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessor,\
|
||||
com.microsoft.azure.spring.autoconfigure.sqlserver.AlwaysEncryptedEnvironmentPostProcessor
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.microsoft.azure.spring.autoconfigure.cosmosdb.DocumentDBAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.cosmosdb.DocumentDbRepositoriesAutoConfiguration,\
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.microsoft.azure.spring.autoconfigure.cosmosdb.CosmosAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.cosmosdb.CosmosDbRepositoriesAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.cosmosdb.CosmosDbReactiveRepositoriesAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.gremlin.GremlinAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.gremlin.GremlinRepositoriesAutoConfiguration,\
|
||||
com.microsoft.azure.spring.autoconfigure.mediaservices.MediaServicesAutoConfiguration,\
|
||||
|
|
|
@ -6,8 +6,7 @@ spring.security.oauth2.client.provider.azure.user-name-attribute=name
|
|||
|
||||
spring.security.oauth2.client.registration.azure.client-authentication-method=post
|
||||
spring.security.oauth2.client.registration.azure.authorization-grant-type=authorization_code
|
||||
spring.security.oauth2.client.registration.azure.redirect-uri-template={baseUrl}/login/oauth2/code/{registrationId}
|
||||
spring.security.oauth2.client.registration.azure.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
|
||||
spring.security.oauth2.client.registration.azure.scope=openid, https://graph.microsoft.com/user.read
|
||||
spring.security.oauth2.client.registration.azure.client-name=Azure
|
||||
spring.security.oauth2.client.registration.azure.provider=azure
|
||||
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
|
||||
import com.azure.data.cosmos.ConnectionPolicy;
|
||||
import com.azure.data.cosmos.RetryOptions;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Ignore
|
||||
public class CosmosAutoConfigurationTest {
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
PropertySettingUtil.setProperties();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
PropertySettingUtil.unsetProperties();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void canSetAllPropertiesToDocumentClient() {
|
||||
// try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
// context.register(CosmosAutoConfiguration.class);
|
||||
// context.refresh();
|
||||
// final CosmosClient cosmosClient = context.getBean(CosmosClient.class);
|
||||
//
|
||||
// // No way to verify the setting of key value and ConsistencyLevel.
|
||||
// final URI uri = cosmosClient.getServiceEndpoint();
|
||||
// assertThat(uri.toString()).isEqualTo(PropertySettingUtil.URI);
|
||||
//
|
||||
// assertThat(cosmosClient.getConnectionPolicy()).isEqualTo(ConnectionPolicy.GetDefault());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void canSetConnectionPolicyToDocumentClient() {
|
||||
// try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
// context.register(CosmosAutoConfiguration.class, ConnectionPolicyConfig.class);
|
||||
// context.refresh();
|
||||
// final CosmosClient cosmosClient = context.getBean(CosmosClient.class);
|
||||
//
|
||||
// final ConnectionPolicy connectionPolicy = cosmosClient;
|
||||
// assertThat(connectionPolicy.requestTimeoutInMillis()).isEqualTo(PropertySettingUtil.REQUEST_TIMEOUT);
|
||||
// assertThat(connectionPolicy.getMediaRequestTimeout()).
|
||||
// isEqualTo(PropertySettingUtil.MEDIA_REQUEST_TIMEOUT);
|
||||
// assertThat(connectionPolicy.getConnectionMode()).isEqualTo(PropertySettingUtil.CONNECTION_MODE);
|
||||
// assertThat(connectionPolicy.getMediaReadMode()).isEqualTo(PropertySettingUtil.MEDIA_READ_MODE);
|
||||
// assertThat(connectionPolicy.getMaxPoolSize()).isEqualTo(PropertySettingUtil.MAX_POOL_SIZE);
|
||||
// assertThat(connectionPolicy.getIdleConnectionTimeout()).
|
||||
// isEqualTo(PropertySettingUtil.IDLE_CONNECTION_TIMEOUT);
|
||||
// // TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
// // assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
// assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.DEFAULT_USER_AGENT_SUFFIX);
|
||||
// assertThat(connectionPolicy.getRetryOptions().getMaxRetryAttemptsOnThrottledRequests()).
|
||||
// isEqualTo(PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_ATTEMPTS_ON_THROTTLED_REQUESTS);
|
||||
// assertThat(connectionPolicy.getRetryOptions().getMaxRetryWaitTimeInSeconds()).
|
||||
// isEqualTo(PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_WAIT_TIME_IN_SECONDS);
|
||||
// assertThat(connectionPolicy.getEnableEndpointDiscovery()).
|
||||
// isEqualTo(PropertySettingUtil.ENABLE_ENDPOINT_DISCOVERY);
|
||||
// assertThat(connectionPolicy.getPreferredLocations().toString()).
|
||||
// isEqualTo(PropertySettingUtil.PREFERRED_LOCATIONS.toString());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void canSetAllowTelemetryFalse() {
|
||||
// PropertySettingUtil.setAllowTelemetryFalse();
|
||||
//
|
||||
// try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
// context.register(CosmosAutoConfiguration.class, ConnectionPolicyConfig.class);
|
||||
// context.refresh();
|
||||
// final DocumentClient documentClient = context.getBean(DocumentClient.class);
|
||||
//
|
||||
// final ConnectionPolicy connectionPolicy = documentClient.getConnectionPolicy();
|
||||
// // TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
// // assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
// assertThat(connectionPolicy.getUserAgentSuffix()).contains(
|
||||
// PropertySettingUtil.DEFAULT_USER_AGENT_SUFFIX);
|
||||
// }
|
||||
// PropertySettingUtil.unsetAllowTelemetry();
|
||||
// }
|
||||
|
||||
@Configuration
|
||||
static class ConnectionPolicyConfig {
|
||||
@Bean
|
||||
public ConnectionPolicy connectionPolicy() {
|
||||
final ConnectionPolicy connectionPolicy = ConnectionPolicy.defaultPolicy();
|
||||
|
||||
connectionPolicy.requestTimeoutInMillis(PropertySettingUtil.REQUEST_TIMEOUT);
|
||||
connectionPolicy.connectionMode(PropertySettingUtil.CONNECTION_MODE);
|
||||
connectionPolicy.maxPoolSize(PropertySettingUtil.MAX_POOL_SIZE);
|
||||
connectionPolicy.idleConnectionTimeoutInMillis(PropertySettingUtil.IDLE_CONNECTION_TIMEOUT);
|
||||
// TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
connectionPolicy.userAgentSuffix(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
|
||||
final RetryOptions retryOptions = new RetryOptions();
|
||||
retryOptions.maxRetryAttemptsOnThrottledRequests(
|
||||
PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_ATTEMPTS_ON_THROTTLED_REQUESTS);
|
||||
retryOptions.maxRetryWaitTimeInSeconds(
|
||||
PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_WAIT_TIME_IN_SECONDS);
|
||||
connectionPolicy.retryOptions(retryOptions);
|
||||
|
||||
connectionPolicy.enableEndpointDiscovery(PropertySettingUtil.ENABLE_ENDPOINT_DISCOVERY);
|
||||
connectionPolicy.preferredLocations(PropertySettingUtil.PREFERRED_LOCATIONS);
|
||||
|
||||
return connectionPolicy;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DocumentDBPropertiesTest {
|
||||
public class CosmosDBPropertiesTest {
|
||||
@Test
|
||||
public void canSetAllProperties() {
|
||||
PropertySettingUtil.setProperties();
|
||||
|
@ -29,7 +29,7 @@ public class DocumentDBPropertiesTest {
|
|||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
final DocumentDBProperties properties = context.getBean(DocumentDBProperties.class);
|
||||
final CosmosDBProperties properties = context.getBean(CosmosDBProperties.class);
|
||||
|
||||
assertThat(properties.getUri()).isEqualTo(PropertySettingUtil.URI);
|
||||
assertThat(properties.getKey()).isEqualTo(PropertySettingUtil.KEY);
|
||||
|
@ -47,7 +47,7 @@ public class DocumentDBPropertiesTest {
|
|||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(Config.class);
|
||||
context.refresh();
|
||||
final DocumentDBProperties properties = context.getBean(DocumentDBProperties.class);
|
||||
final CosmosDBProperties properties = context.getBean(CosmosDBProperties.class);
|
||||
|
||||
assertThat(properties.isAllowTelemetry()).isEqualTo(PropertySettingUtil.ALLOW_TELEMETRY_FALSE);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class DocumentDBPropertiesTest {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(DocumentDBProperties.class)
|
||||
@EnableConfigurationProperties(CosmosDBProperties.class)
|
||||
static class Config {
|
||||
}
|
||||
}
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.documentdb.DocumentClient;
|
||||
import com.azure.data.cosmos.CosmosClient;
|
||||
import com.microsoft.azure.spring.autoconfigure.cosmosdb.domain.Person;
|
||||
import com.microsoft.azure.spring.autoconfigure.cosmosdb.domain.PersonRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.DocumentDbFactory;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbTemplate;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.convert.MappingDocumentDbConverter;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableDocumentDbRepositories;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.CosmosDbFactory;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.CosmosTemplate;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.core.convert.MappingCosmosConverter;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -28,21 +28,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@Ignore
|
||||
public class DocumentDbRepositoriesAutoConfigurationUnitTest {
|
||||
public class CosmosDbRepositoriesAutoConfigurationUnitTest {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@InjectMocks
|
||||
private DocumentDbTemplate dbOperations;
|
||||
private CosmosTemplate cosmosTemplate;
|
||||
|
||||
@Mock
|
||||
private DocumentDbFactory documentDbFactory;
|
||||
private CosmosDbFactory cosmosDbFactory;
|
||||
|
||||
@Mock
|
||||
private MappingDocumentDbConverter mappingDocumentDbConverter;
|
||||
private MappingCosmosConverter mappingCosmosConverter;
|
||||
|
||||
@Mock
|
||||
private DocumentClient documentClient;
|
||||
private CosmosClient cosmosClient;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
|
@ -67,8 +67,8 @@ public class DocumentDbRepositoriesAutoConfigurationUnitTest {
|
|||
private void prepareApplicationContext(Class<?>... configurationClasses) {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(configurationClasses);
|
||||
this.context.register(DocumentDbRepositoriesAutoConfiguration.class);
|
||||
this.context.getBeanFactory().registerSingleton(DocumentDbTemplate.class.getName(), dbOperations);
|
||||
this.context.register(CosmosDbRepositoriesAutoConfiguration.class);
|
||||
this.context.getBeanFactory().registerSingleton(CosmosTemplate.class.getName(), cosmosTemplate);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ public class DocumentDbRepositoriesAutoConfigurationUnitTest {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@EnableDocumentDbRepositories("foo.bar")
|
||||
@TestAutoConfigurationPackage(DocumentDbRepositoriesAutoConfigurationUnitTest.class)
|
||||
@EnableCosmosRepositories("foo.bar")
|
||||
@TestAutoConfigurationPackage(CosmosDbRepositoriesAutoConfigurationUnitTest.class)
|
||||
protected static class InvalidCustomConfiguration {
|
||||
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See LICENSE in the project root for
|
||||
* license information.
|
||||
*/
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
|
||||
import com.microsoft.azure.documentdb.ConnectionPolicy;
|
||||
import com.microsoft.azure.documentdb.DocumentClient;
|
||||
import com.microsoft.azure.documentdb.RetryOptions;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@Ignore
|
||||
public class DocumentDBAutoConfigurationTest {
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
PropertySettingUtil.setProperties();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
PropertySettingUtil.unsetProperties();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSetAllPropertiesToDocumentClient() {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(DocumentDBAutoConfiguration.class);
|
||||
context.refresh();
|
||||
final DocumentClient documentClient = context.getBean(DocumentClient.class);
|
||||
|
||||
// No way to verify the setting of key value and ConsistencyLevel.
|
||||
final URI uri = documentClient.getServiceEndpoint();
|
||||
assertThat(uri.toString()).isEqualTo(PropertySettingUtil.URI);
|
||||
|
||||
assertThat(documentClient.getConnectionPolicy()).isEqualTo(ConnectionPolicy.GetDefault());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSetConnectionPolicyToDocumentClient() {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(DocumentDBAutoConfiguration.class, ConnectionPolicyConfig.class);
|
||||
context.refresh();
|
||||
final DocumentClient documentClient = context.getBean(DocumentClient.class);
|
||||
|
||||
final ConnectionPolicy connectionPolicy = documentClient.getConnectionPolicy();
|
||||
assertThat(connectionPolicy.getRequestTimeout()).isEqualTo(PropertySettingUtil.REQUEST_TIMEOUT);
|
||||
assertThat(connectionPolicy.getMediaRequestTimeout()).
|
||||
isEqualTo(PropertySettingUtil.MEDIA_REQUEST_TIMEOUT);
|
||||
assertThat(connectionPolicy.getConnectionMode()).isEqualTo(PropertySettingUtil.CONNECTION_MODE);
|
||||
assertThat(connectionPolicy.getMediaReadMode()).isEqualTo(PropertySettingUtil.MEDIA_READ_MODE);
|
||||
assertThat(connectionPolicy.getMaxPoolSize()).isEqualTo(PropertySettingUtil.MAX_POOL_SIZE);
|
||||
assertThat(connectionPolicy.getIdleConnectionTimeout()).
|
||||
isEqualTo(PropertySettingUtil.IDLE_CONNECTION_TIMEOUT);
|
||||
// TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
// assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.DEFAULT_USER_AGENT_SUFFIX);
|
||||
assertThat(connectionPolicy.getRetryOptions().getMaxRetryAttemptsOnThrottledRequests()).
|
||||
isEqualTo(PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_ATTEMPTS_ON_THROTTLED_REQUESTS);
|
||||
assertThat(connectionPolicy.getRetryOptions().getMaxRetryWaitTimeInSeconds()).
|
||||
isEqualTo(PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_WAIT_TIME_IN_SECONDS);
|
||||
assertThat(connectionPolicy.getEnableEndpointDiscovery()).
|
||||
isEqualTo(PropertySettingUtil.ENABLE_ENDPOINT_DISCOVERY);
|
||||
assertThat(connectionPolicy.getPreferredLocations().toString()).
|
||||
isEqualTo(PropertySettingUtil.PREFERRED_LOCATIONS.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSetAllowTelemetryFalse() {
|
||||
PropertySettingUtil.setAllowTelemetryFalse();
|
||||
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
context.register(DocumentDBAutoConfiguration.class, ConnectionPolicyConfig.class);
|
||||
context.refresh();
|
||||
final DocumentClient documentClient = context.getBean(DocumentClient.class);
|
||||
|
||||
final ConnectionPolicy connectionPolicy = documentClient.getConnectionPolicy();
|
||||
// TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
// assertThat(connectionPolicy.getUserAgentSuffix()).contains(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
assertThat(connectionPolicy.getUserAgentSuffix()).contains(
|
||||
PropertySettingUtil.DEFAULT_USER_AGENT_SUFFIX);
|
||||
}
|
||||
PropertySettingUtil.unsetAllowTelemetry();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class ConnectionPolicyConfig {
|
||||
@Bean
|
||||
public ConnectionPolicy connectionPolicy() {
|
||||
final ConnectionPolicy connectionPolicy = ConnectionPolicy.GetDefault();
|
||||
|
||||
connectionPolicy.setRequestTimeout(PropertySettingUtil.REQUEST_TIMEOUT);
|
||||
connectionPolicy.setMediaRequestTimeout(PropertySettingUtil.MEDIA_REQUEST_TIMEOUT);
|
||||
connectionPolicy.setConnectionMode(PropertySettingUtil.CONNECTION_MODE);
|
||||
connectionPolicy.setMediaReadMode(PropertySettingUtil.MEDIA_READ_MODE);
|
||||
connectionPolicy.setMaxPoolSize(PropertySettingUtil.MAX_POOL_SIZE);
|
||||
connectionPolicy.setIdleConnectionTimeout(PropertySettingUtil.IDLE_CONNECTION_TIMEOUT);
|
||||
// TODO (data) User agent from configured ConnectionPolicy is not taken
|
||||
connectionPolicy.setUserAgentSuffix(PropertySettingUtil.USER_AGENT_SUFFIX);
|
||||
|
||||
final RetryOptions retryOptions = new RetryOptions();
|
||||
retryOptions.setMaxRetryAttemptsOnThrottledRequests(
|
||||
PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_ATTEMPTS_ON_THROTTLED_REQUESTS);
|
||||
retryOptions.setMaxRetryWaitTimeInSeconds(
|
||||
PropertySettingUtil.RETRY_OPTIONS_MAX_RETRY_WAIT_TIME_IN_SECONDS);
|
||||
connectionPolicy.setRetryOptions(retryOptions);
|
||||
|
||||
connectionPolicy.setEnableEndpointDiscovery(PropertySettingUtil.ENABLE_ENDPOINT_DISCOVERY);
|
||||
connectionPolicy.setPreferredLocations(PropertySettingUtil.PREFERRED_LOCATIONS);
|
||||
|
||||
return connectionPolicy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,8 @@
|
|||
*/
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb;
|
||||
|
||||
import com.microsoft.azure.documentdb.ConnectionMode;
|
||||
import com.microsoft.azure.documentdb.ConsistencyLevel;
|
||||
import com.microsoft.azure.documentdb.MediaReadMode;
|
||||
import com.azure.data.cosmos.ConnectionMode;
|
||||
import com.azure.data.cosmos.ConsistencyLevel;
|
||||
import com.microsoft.azure.utils.PropertyLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -19,11 +18,10 @@ public class PropertySettingUtil {
|
|||
public static final String DATABASE_NAME = "test";
|
||||
public static final boolean ALLOW_TELEMETRY_TRUE = true;
|
||||
public static final boolean ALLOW_TELEMETRY_FALSE = false;
|
||||
public static final ConsistencyLevel CONSISTENCY_LEVEL = ConsistencyLevel.Strong;
|
||||
public static final ConsistencyLevel CONSISTENCY_LEVEL = ConsistencyLevel.STRONG;
|
||||
public static final int REQUEST_TIMEOUT = 4;
|
||||
public static final int MEDIA_REQUEST_TIMEOUT = 3;
|
||||
public static final ConnectionMode CONNECTION_MODE = ConnectionMode.DirectHttps;
|
||||
public static final MediaReadMode MEDIA_READ_MODE = MediaReadMode.Streamed;
|
||||
public static final ConnectionMode CONNECTION_MODE = ConnectionMode.DIRECT;
|
||||
public static final int MAX_POOL_SIZE = 1;
|
||||
public static final int IDLE_CONNECTION_TIMEOUT = 2;
|
||||
public static final String USER_AGENT_SUFFIX = "suffix";
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
package com.microsoft.azure.spring.autoconfigure.cosmosdb.domain;
|
||||
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository;
|
||||
import com.microsoft.azure.spring.data.cosmosdb.repository.CosmosRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PersonRepository extends DocumentDbRepository<Person, String> {
|
||||
public interface PersonRepository extends CosmosRepository<Person, String> {
|
||||
}
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-spring-boot-build</artifactId>
|
||||
<version>2.1.8-SNAPSHOT</version>
|
||||
<version>2.2.0.M1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Azure Spring Boot Build</name>
|
||||
|
|
Загрузка…
Ссылка в новой задаче