You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this section, neither the configurations nor the code have any authentication operations. However, connecting to Azure service requires authentication. To complete the authentication, you need to use Azure Identity. Spring Cloud Azure uses `DefaultAzureCredential`, which is provided by Azure Identity to help you get credentials without any code changes.
97
+
98
+
`DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code. For more information, see the [Default Azure credential](/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential) section of [Authenticate Azure-hosted Java applications](/azure/developer/java/sdk/identity-azure-hosted-auth).
99
+
100
+
To use Azure CLI, Visual Studio Code, PowerShell or other methods to complete the authentication in local development environments, see [Azure authentication in Java development environments](/azure/developer/java/sdk/identity-dev-env-auth). To complete the authentication in Azure hosting environments, we recommend using managed identity. For more information, see [What are managed identities for Azure resources?](/azure/active-directory/managed-identities-azure-resources/overview)
Configure the Azure Database for MySQL credentials in the `application.yml` configuration file in the `cosmos/spring-cloud-azure-starter-data-cosmos/spring-cloud-azure-data-cosmos-sample` directory. Replace the values of `${AZURE_COSMOS_ENDPOINT}` and `${COSMOS_DATABASE}`.
@@ -108,17 +116,40 @@ spring:
108
116
109
117
After creating the Azure Cosmos DB account, database and container, Spring Boot/Spring Data will connect to the database and container for `delete`, `add` and `find` operations.
110
118
111
-
> [!TIP]
112
-
> In this section, neither the configurations nor the code have any authentication operations. However, connecting to Azure service requires authentication. To complete the authentication, you need to use Azure Identity. Spring Cloud Azure uses `DefaultAzureCredential`, which is provided by Azure Identity to help you get credentials without any code changes.
113
-
>
114
-
> `DefaultAzureCredential` supports multiple authentication methods and determines which method should be used at runtime. This approach enables your app to use different authentication methods in different environments (local vs. production) without implementing environment-specific code. For more information, see the [Default Azure credential](/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential) section of [Authenticate Azure-hosted Java applications](/azure/developer/java/sdk/identity-azure-hosted-auth).
115
-
>
116
-
> To use Azure CLI, Visual Studio Code, PowerShell or other methods to complete the authentication in local development environments, see [Azure authentication in Java development environments](/azure/developer/java/sdk/identity-dev-env-auth). To complete the authentication in Azure hosting environments, we recommend using managed identity. For more information, see [What are managed identities for Azure resources?](/azure/active-directory/managed-identities-azure-resources/overview)
117
-
118
119
### Java source
119
120
120
-
The sample code has already been added, you don't need to add any code.
121
+
The Spring Data value-add also comes from its simple, clean, standardized and platform-independent interface for operating on datastores. Building on the Spring Data GitHub sample linked above, below are CRUD and query samples for manipulating Azure Cosmos DB documents with Spring Datan Azure Cosmos DB.
122
+
123
+
* Item creation and updates by using the `save` method.
124
+
125
+
```java
126
+
// Save the User class to Azure Cosmos DB database.
127
+
final Mono<User> saveUserMono = repository.save(testUser);
128
+
```
129
+
130
+
* Point-reads using the derived query method defined in the repository. The `findById` performs point-reads for `repository`. The fields mentioned in the method name cause Spring Data to execute a point-read defined by the `id` field:
131
+
132
+
```java
133
+
// Nothing happens until we subscribe to these Monos.
134
+
// findById will not return the user as user is not present.
135
+
final Mono<User> findByIdMono = repository.findById(testUser.getId());
136
+
final User findByIdUser = findByIdMono.block();
137
+
Assert.isNull(findByIdUser, "User must be null");
138
+
```
139
+
140
+
* Item deletes using `deleteAll`:
141
+
142
+
```java
143
+
repository.deleteAll().block();
144
+
LOGGER.info("Deleted all data in container.");
145
+
```
146
+
147
+
* Derived query based on repository method name. Spring Data implements the `repository` `findByFirstName` method as a Java SDK SQL query on the `firstName` field (this query could not be implemented as a point-read):
121
148
149
+
```java
150
+
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
151
+
```
152
+
122
153
## [Password](#tab/password)
123
154
124
155
### Application configuration file
@@ -139,18 +170,44 @@ Once you create an Azure Cosmos DB account, database, and container, just fill-i
139
170
140
171
### Java source
141
172
142
-
The sample code has already been added, you don't need to add any code.
173
+
The Spring Data value-add also comes from its simple, clean, standardized and platform-independent interface for operating on datastores. Building on the Spring Data GitHub sample linked above, below are CRUD and query samples for manipulating Azure Cosmos DB documents with Spring Datan Azure Cosmos DB.
143
174
144
-
---
175
+
* Item creation and updates by using the `save` method.
176
+
177
+
```java
178
+
// Save the User class to Azure Cosmos DB database.
179
+
final Mono<User> saveUserMono = repository.save(testUser);
180
+
```
181
+
182
+
* Point-reads using the derived query method defined in the repository. The `findById` performs point-reads for `repository`. The fields mentioned in the method name cause Spring Data to execute a point-read defined by the `id` field:
183
+
184
+
```java
185
+
// Nothing happens until we subscribe to these Monos.
186
+
// findById will not return the user as user is not present.
187
+
final Mono<User> findByIdMono = repository.findById(testUser.getId());
188
+
final User findByIdUser = findByIdMono.block();
189
+
Assert.isNull(findByIdUser, "User must be null");
190
+
```
145
191
192
+
* Item deletes using `deleteAll`:
193
+
194
+
```java
195
+
repository.deleteAll().block();
196
+
LOGGER.info("Deleted all data in container.");
197
+
```
198
+
199
+
* Derived query based on repository method name. Spring Data implements the `repository` `findByFirstName` method as a Java SDK SQL query on the `firstName` field (this query could not be implemented as a point-read):
200
+
201
+
```java
202
+
final Flux<User> firstNameUserFlux = repository.findByFirstName("testFirstName");
203
+
```
204
+
205
+
---
146
206
147
207
## Run the app
148
208
149
209
Now go back to the Azure portal to get your connection string information and launch the app with your endpoint information. This enables your app to communicate with your hosted database.
150
210
151
-
>[!TIP]
152
-
> Before starting the following sections, replace the variables in *application.yml* with real values. If you use Passwordless authentication, [create the custom role](/azure/cosmos-db/nosql/quickstart-java?tabs=passwordlesssync%2Csign-in-azure-cli#create-the-custom-role) and use Azure CLI, Visual Studio Code, PowerShell, or other methods to complete the authentication.
153
-
154
211
1. In the git terminal window, `cd` to the sample code folder.
0 commit comments