Skip to content

Commit dd73bf1

Browse files
authored
Merge pull request #295034 from mrm9084/SpringUpdates
App Config - Spring updates
2 parents 725dd77 + 8085b04 commit dd73bf1

File tree

4 files changed

+188
-173
lines changed

4 files changed

+188
-173
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-java-spring-app.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: mrm9084
77
ms.service: azure-app-configuration
88
ms.devlang: java
99
ms.topic: tutorial
10-
ms.date: 12/04/2024
10+
ms.date: 06/18/2025
1111
ms.custom: devx-track-java, devx-track-extended-java
1212
ms.author: mametcal
1313
#Customer intent: As a Java Spring developer, I want to dynamically update my app to use the latest configuration data in App Configuration.
@@ -29,7 +29,7 @@ Refresh allows you to update your configuration values without having to restart
2929

3030
To use manual refresh, start with a Spring Boot app that uses App Configuration, such as the app you create by following the [Spring Boot quickstart for App Configuration](quickstart-java-spring-app.md).
3131

32-
App Configuration exposes `AppConfigurationRefresh`, which can be used to check if the cache is expired. If it's expired, a refresh is triggered.
32+
App Configuration exposes `AppConfigurationRefresh`, which checks if the refresh interval has passed. If the refresh interval has passed, it triggers a refresh.
3333

3434
1. To use `AppConfigurationRefresh`, update HelloController.
3535

@@ -59,6 +59,13 @@ App Configuration exposes `AppConfigurationRefresh`, which can be used to check
5959

6060
`AppConfigurationRefresh`'s `refreshConfigurations()` returns a `Mono` that is true if a refresh is triggered, and false if not. False means either the cache expiration time isn't expired, there was no change, or another thread is currently checking for a refresh.
6161

62+
> [!NOTE]
63+
> For libraries such as Spring WebFlux that require non-blocking calls, `refreshConfigurations()` needs to be wrapped in a thread as loading configurations requires a blocking call.
64+
>
65+
> ```java
66+
> new Thread(() -> refresh.refreshConfigurations()).start();
67+
> ```
68+
6269
1. To enable refresh update `bootstrap.properties`:
6370

6471
```properties
@@ -106,8 +113,8 @@ App Configuration exposes `AppConfigurationRefresh`, which can be used to check
106113

107114
1. Refresh the browser page twice to see the new message displayed. The first time triggers the refresh, the second loads the changes.
108115

109-
> [!NOTE]
110-
> The library only checks for changes on the after the refresh interval has passed. If the period hasn't passed then no change is displayed. Wait for the period to pass, then trigger the refresh check.
116+
> [!NOTE]
117+
> The library checks for changes only after the refresh interval passes. If the refresh interval hasn't passed, it doesn't check for changes. Wait for the interval to pass, then trigger the refresh check.
111118

112119
## Use automated refresh
113120

@@ -119,7 +126,7 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `spr
119126
<dependency>
120127
<groupId>com.azure.spring</groupId>
121128
<artifactId>spring-cloud-azure-appconfiguration-config-web</artifactId>
122-
<version>5.18.0</version>
129+
<version>5.22.0</version>
123130
</dependency>
124131
```
125132

@@ -170,8 +177,8 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `spr
170177

171178
1. Refresh the browser page twice to see the new message displayed. The first time triggers the refresh, the second loads the changes, as the first request returns using the original scope.
172179

173-
> [!NOTE]
174-
> The library only checks for changes on after the refresh interval has passed. If the refresh interval hasn't passed, then it doesn't check for changes. Wait for the interval to pass, then trigger the refresh check.
180+
> [!NOTE]
181+
> The library checks for changes only after the refresh interval passes. If the refresh interval hasn't passed, it doesn't check for changes. Wait for the interval to pass, then trigger the refresh check.
175182

176183
## Next steps
177184

articles/azure-app-configuration/enable-dynamic-configuration-java-spring-push-refresh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: azure-app-configuration
99
ms.devlang: java
1010
ms.custom: devx-track-extended-java
1111
ms.topic: tutorial
12-
ms.date: 12/04/2024
12+
ms.date: 06/18/2025
1313
ms.author: mametcal
1414
#Customer intent: I want to use push refresh to dynamically update my app to use the latest configuration data in App Configuration.
1515
---
@@ -63,7 +63,7 @@ In this tutorial, you learn how to:
6363
<dependency>
6464
<groupId>com.azure.spring</groupId>
6565
<artifactId>spring-cloud-azure-dependencies</artifactId>
66-
<version>5.18.0</version>
66+
<version>5.22.0</version>
6767
<type>pom</type>
6868
<scope>import</scope>
6969
</dependency>

articles/azure-app-configuration/quickstart-feature-flag-spring-boot.md

Lines changed: 120 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: mrm9084
55
ms.service: azure-app-configuration
66
ms.devlang: java
77
ms.topic: quickstart
8-
ms.date: 12/04/2024
8+
ms.date: 06/18/2025
99
ms.author: mametcal
1010
ms.custom: devx-track-java, mode-other
1111
#Customer intent: As an Spring Boot developer, I want to use feature flags to control feature availability quickly and confidently.
@@ -71,7 +71,7 @@ To create a new Spring Boot project:
7171
<dependency>
7272
<groupId>com.azure.spring</groupId>
7373
<artifactId>spring-cloud-azure-dependencies</artifactId>
74-
<version>5.18.0</version>
74+
<version>5.22.0</version>
7575
<type>pom</type>
7676
<scope>import</scope>
7777
</dependency>
@@ -80,68 +80,87 @@ To create a new Spring Boot project:
8080
```
8181

8282
> [!NOTE]
83-
> * There is a non-web Feature Management Library that doesn't have a dependency on spring-web. Refer to GitHub's [documentation](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/spring/spring-cloud-azure-feature-management) for differences.
83+
> * There's a non-web Feature Management Library that doesn't have a dependency on spring-web. Refer to GitHub's [documentation](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/spring/spring-cloud-azure-feature-management) for differences.
8484
8585
## Connect to an App Configuration store
8686

87+
1. Navigate to the `resources` directory of your app and open the `bootstrap.properties` or `bootstrap.yaml` file. If the file doesn't exist, create it.
8788

88-
1. Navigate to the `resources` directory of your app and open the `bootstrap.properties` or `bootstrap.yaml` file. If the file does not exist, create it. Add the following line to the file.
89-
90-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
91-
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application. Create a new file named *AppConfigCredential.java* and add the following lines:
92-
93-
If you are using a properties file, use the following code:
94-
```properties
95-
spring.cloud.azure.appconfiguration.stores[0].endpoint= ${APP_CONFIGURATION_ENDPOINT}
96-
spring.cloud.azure.appconfiguration.stores[0].feature-flags.enabled=true
97-
```
89+
You can connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
9890

99-
If you are using a yaml file, use the following code:
100-
```yaml
101-
spring:
102-
cloud:
103-
azure:
104-
appconfiguration:
105-
stores[0]:
106-
feature-flags:
107-
enabled: 'true'
108-
connection-string: ${APP_CONFIGURATION_CONNECTION_STRING}
109-
```
110-
111-
Additionally, you need to add the following code to your project, unless you want to use Managed Identity:
112-
113-
```java
114-
import org.springframework.stereotype.Component;
91+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
92+
1. Update your configuration files.
93+
94+
If you're using a properties file, use the following code:
95+
```properties
96+
spring.cloud.azure.appconfiguration.stores[0].endpoint= ${APP_CONFIGURATION_ENDPOINT}
97+
spring.cloud.azure.appconfiguration.stores[0].feature-flags.enabled=true
98+
```
99+
100+
If you're using a yaml file, use the following code:
101+
```yaml
102+
spring:
103+
cloud:
104+
azure:
105+
appconfiguration:
106+
stores:
107+
-
108+
feature-flags:
109+
enabled: true
110+
endpoint: ${APP_CONFIGURATION_ENDPOINT}
111+
```
112+
113+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
114+
115+
1. Add the following code to your project, unless you want to use Managed Identity. Create a new file named `AppConfigCredential.java`:
115116
116-
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
117-
import com.azure.identity.DefaultAzureCredentialBuilder;
118-
import com.azure.spring.cloud.appconfiguration.config.ConfigurationClientCustomizer;
117+
```java
118+
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
119+
import com.azure.identity.DefaultAzureCredentialBuilder;
120+
import com.azure.spring.cloud.appconfiguration.config.ConfigurationClientCustomizer;
121+
122+
public class AppConfigCredential implements ConfigurationClientCustomizer {
123+
124+
@Override
125+
public void customize(ConfigurationClientBuilder builder, String endpoint) {
126+
builder.credential(new DefaultAzureCredentialBuilder().build());
127+
}
128+
}
129+
```
119130
120-
@Component
121-
public class AppConfigCredential implements ConfigurationClientCustomizer {
131+
1. Create a new file named `MyConfiguration.java` and add the following lines:
122132
123-
@Override
124-
public void customize(ConfigurationClientBuilder builder, String endpoint) {
125-
builder.credential(new DefaultAzureCredentialBuilder().build());
133+
```java
134+
import org.springframework.context.annotation.Bean;
135+
import org.springframework.context.annotation.Configuration;
136+
137+
@Configuration
138+
public class MyConfiguration {
139+
140+
141+
@Bean
142+
public AppConfigCredential clientSetup() {
143+
return new AppConfigCredential();
144+
}
145+
126146
}
127-
}
128-
```
147+
```
129148
130-
And add configuration Bootstrap Configuration, by creating `spring.factories` file under `resources/META-INF` directory and add the following lines and updating `com.example.MyApplication` with your application name and package:
149+
1. Add configuration Bootstrap Configuration, by creating `spring.factories` file under `resources/META-INF` directory and add the following lines and updating `com.example.MyConfiguration` with your application package:
131150
132-
```factories
133-
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
134-
com.example.MyApplication
135-
```
151+
```factories
152+
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
153+
com.example.MyConfiguration
154+
```
136155
137156
### [Connection string](#tab/connection-string)
138-
If you are using a properties file, use the following code:
139-
```properties
157+
If you are using a properties file, use the following code:
158+
```properties
140159
spring.cloud.azure.appconfiguration.stores[0].endpoint= ${APP_CONFIGURATION_CONNECTION_STRING}
141160
spring.cloud.azure.appconfiguration.stores[0].feature-flags.enabled=true
142161
```
143162
144-
If you are using a yaml file, use the following code:
163+
If you are using a yaml file, use the following code:
145164
```yaml
146165
spring:
147166
cloud:
@@ -154,81 +173,28 @@ To create a new Spring Boot project:
154173
```
155174
---
156175
157-
1. Set an environment variable.
158-
159-
### [Microsoft Entra ID (recommended)](#tab/entra-id)
160-
Set the environment variable named **APP_CONFIGURATION_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
161-
162-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
163-
164-
```cmd
165-
setx APP_CONFIGURATION_ENDPOINT "endpoint-of-your-app-configuration-store"
166-
```
167-
168-
If you use PowerShell, run the following command:
169-
170-
```powershell
171-
$Env:APP_CONFIGURATION_ENDPOINT = "<endpoint-of-your-app-configuration-store>"
172-
```
173-
174-
If you use macOS or Linux, run the following command:
175-
176-
```bash
177-
export APP_CONFIGURATION_ENDPOINT='<endpoint-of-your-app-configuration-store>'
178-
```
179-
180-
### [Connection string](#tab/connection-string)
181-
Set the environment variable named **APP_CONFIGURATION_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access keys* of your store in the Azure portal.
182-
183-
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
184-
185-
```cmd
186-
setx APP_CONFIGURATION_CONNECTION_STRING "<connection-string-of-your-app-configuration-store>"
187-
```
188-
189-
If you use PowerShell, run the following command:
190-
191-
```powershell
192-
$Env:APP_CONFIGURATION_CONNECTION_STRING = "<connection-string-of-your-app-configuration-store>"
193-
```
194-
195-
If you use macOS or Linux, run the following command:
196-
197-
```bash
198-
export APP_CONFIGURATION_CONNECTION_STRING='<connection-string-of-your-app-configuration-store>'
199-
```
200-
---
201-
202-
Restart the command prompt to allow the change to take effect. Print the value of the environment variable to validate that it is set properly.
203-
204-
---
205-
206176
1. Create a new Java file named *HelloController.java* in the package directory of your app.
207177
208178
```java
209179
package com.example.demo;
210180
211-
import org.springframework.boot.context.properties.ConfigurationProperties;
181+
import org.springframework.beans.factory.annotation.Autowired;
212182
import org.springframework.stereotype.Controller;
213183
import org.springframework.ui.Model;
184+
import org.springframework.web.bind.annotation.GetMapping;
214185
215186
import com.azure.spring.cloud.feature.management.FeatureManager;
216-
import org.springframework.web.bind.annotation.GetMapping;
217187
218188
219189
@Controller
220-
@ConfigurationProperties("controller")
221190
public class HelloController {
222191
192+
@Autowired
223193
private FeatureManager featureManager;
224194
225-
public HelloController(FeatureManager featureManager) {
226-
this.featureManager = featureManager;
227-
}
228-
229195
@GetMapping("/welcome")
230196
public String mainWithParam(Model model) {
231-
model.addAttribute("Beta", featureManager.isEnabledAsync("Beta").block());
197+
model.addAttribute("Beta", featureManager.isEnabled("Beta"));
232198
return "welcome";
233199
}
234200
}
@@ -326,6 +292,56 @@ To create a new Spring Boot project:
326292
327293
## Build and run the app locally
328294
295+
1. Set an environment variable.
296+
297+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
298+
Set the environment variable named **APP_CONFIGURATION_ENDPOINT** to the endpoint of your App Configuration store found under the *Overview* of your store in the Azure portal.
299+
300+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
301+
302+
```cmd
303+
setx APP_CONFIGURATION_ENDPOINT "endpoint-of-your-app-configuration-store"
304+
```
305+
306+
If you use PowerShell, run the following command:
307+
308+
```powershell
309+
$Env:APP_CONFIGURATION_ENDPOINT = "<endpoint-of-your-app-configuration-store>"
310+
```
311+
312+
If you use macOS or Linux, run the following command:
313+
314+
```bash
315+
export APP_CONFIGURATION_ENDPOINT='<endpoint-of-your-app-configuration-store>'
316+
```
317+
318+
### [Connection string](#tab/connection-string)
319+
320+
Set the environment variable named **APP_CONFIGURATION_CONNECTION_STRING** to the read-only connection string of your App Configuration store found under *Access settings* of your store in the Azure portal.
321+
322+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
323+
324+
```cmd
325+
setx APP_CONFIGURATION_CONNECTION_STRING "<connection-string-of-your-app-configuration-store>"
326+
```
327+
328+
If you use PowerShell, run the following command:
329+
330+
```powershell
331+
$Env:APP_CONFIGURATION_CONNECTION_STRING = "<connection-string-of-your-app-configuration-store>"
332+
```
333+
334+
If you use macOS or Linux, run the following command:
335+
336+
```bash
337+
export APP_CONFIGURATION_CONNECTION_STRING='<connection-string-of-your-app-configuration-store>'
338+
```
339+
---
340+
341+
Restart the command prompt to allow the change to take effect. Print the value of the environment variable to validate that it is set properly.
342+
343+
---
344+
329345
1. Build your Spring Boot application with Maven and run it.
330346
331347
```shell

0 commit comments

Comments
 (0)