Skip to content

Commit 74bf6d2

Browse files
Merge pull request #192985 from mrm9084/AppConfigSpringUpdates
App Configuration Spring Updates
2 parents 9052639 + 965d7ef commit 74bf6d2

7 files changed

+184
-95
lines changed

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

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,112 @@ author: mrm9084
77
ms.service: azure-app-configuration
88
ms.devlang: java
99
ms.topic: tutorial
10-
ms.date: 12/09/2020
10+
ms.date: 05/02/2022
1111
ms.custom: devx-track-java
1212
ms.author: mametcal
1313

1414
#Customer intent: As a Java Spring developer, I want to dynamically update my app to use the latest configuration data in App Configuration.
1515
---
1616
# Tutorial: Use dynamic configuration in a Java Spring app
1717

18-
App Configuration has two libraries for Spring. `azure-spring-cloud-appconfiguration-config` requires Spring Boot and takes a dependency on `spring-cloud-context`. `azure-spring-cloud-appconfiguration-config-web` requires Spring Web along with Spring Boot. Both libraries support manual triggering to check for refreshed configuration values. `azure-spring-cloud-appconfiguration-config-web` also adds support for automatic checking of configuration refresh.
18+
App Configuration has two libraries for Spring.
1919

20-
Refresh allows you to refresh your configuration values without having to restart your application, though it will cause all beans in the `@RefreshScope` to be recreated. The client library caches a hash ID of the currently loaded configurations to avoid too many calls to the configuration store. The refresh operation doesn't update the value until the cached value has expired, even when the value has changed in the configuration store. The default expiration time for each request is 30 seconds. It can be overridden if necessary.
20+
* `azure-spring-cloud-appconfiguration-config` requires Spring Boot and takes a dependency on `spring-cloud-context`.
21+
* `azure-spring-cloud-appconfiguration-config-web` requires Spring Web along with Spring Boot, and also adds support for automatic checking of configuration refresh.
2122

22-
`azure-spring-cloud-appconfiguration-config-web`'s automated refresh is triggered based off activity, specifically Spring Web's `ServletRequestHandledEvent`. If a `ServletRequestHandledEvent` is not triggered, `azure-spring-cloud-appconfiguration-config-web`'s automated refresh will not trigger a refresh even if the cache expiration time has expired.
23+
Both libraries support manual triggering to check for refreshed configuration values.
24+
25+
Refresh allows you to update your configuration values without having to restart your application, though it will cause all beans in the `@RefreshScope` to be recreated. It checks for any changes to configured triggers, including metadata. By default, the minimum amount of time between checks for changes, refresh interval, is set to 30 seconds.
26+
27+
`azure-spring-cloud-appconfiguration-config-web`'s automated refresh is triggered based on activity, specifically Spring Web's `ServletRequestHandledEvent`. If a `ServletRequestHandledEvent` is not triggered, `azure-spring-cloud-appconfiguration-config-web`'s automated refresh will not trigger a refresh even if the cache expiration time has expired.
2328

2429
## Use manual refresh
2530

31+
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).
32+
2633
App Configuration exposes `AppConfigurationRefresh` which can be used to check if the cache is expired and if it is expired trigger a refresh.
2734

28-
```java
29-
import com.azure.spring.cloud.config.AppConfigurationRefresh;
35+
1. Update HelloController to use `AppConfigurationRefresh`.
36+
37+
```java
38+
import com.azure.spring.cloud.config.AppConfigurationRefresh;
39+
40+
...
41+
42+
import com.azure.spring.cloud.config.AppConfigurationRefresh;
43+
44+
@RestController
45+
public class HelloController {
46+
private final MessageProperties properties;
47+
48+
@Autowired(required = false)
49+
private AppConfigurationRefresh refresh;
50+
51+
public HelloController(MessageProperties properties) {
52+
this.properties = properties;
53+
}
54+
55+
@GetMapping
56+
public String getMessage() throws InterruptedException, ExecutionException {
57+
if (refresh != null) {
58+
refresh.refreshConfigurations();
59+
}
60+
return "Message: " + properties.getMessage();
61+
}
62+
}
63+
```
3064

31-
...
65+
`AppConfigurationRefresh`'s `refreshConfigurations()` returns a `Future` that is true if a refresh has been triggered, and false if not. False means either the cache expiration time hasn't expired, there was no change, or another thread is currently checking for a refresh.
3266

33-
@Autowired
34-
private AppConfigurationRefresh appConfigurationRefresh;
67+
1. Update `bootstrap.properties` to enable refresh
3568

36-
...
69+
```properties
70+
spring.cloud.azure.appconfiguration.stores[0].monitoring.enabled=true
71+
spring.cloud.azure.appconfiguration.stores[0].monitoring.refresh-interval= 30s
72+
spring.cloud.azure.appconfiguration.stores[0].monitoring.triggers[0].key=sentinel
73+
```
3774

38-
public void myConfigurationRefreshCheck() {
39-
Future<Boolean> triggeredRefresh = appConfigurationRefresh.refreshConfigurations();
40-
}
41-
```
75+
1. Open the **Azure Portal** and navigate to your App Configuration resource associated with your application. Select **Configuration Explorer** under **Operations** and create a new key-value pair by selecting **+ Create** > **Key-value** to add the following parameters:
76+
77+
| Key | Value |
78+
|---|---|
79+
| sentinel | 1 |
80+
81+
Leave **Label** and **Content Type** empty for now.
82+
83+
1. Select **Apply**.
84+
85+
1. Build your Spring Boot application with Maven and run it.
86+
87+
```shell
88+
mvn clean package
89+
mvn spring-boot:run
90+
```
91+
92+
1. Open a browser window, and go to the URL: `http://localhost:8080`. You will see the message associated with your key.
4293

43-
`AppConfigurationRefresh`'s `refreshConfigurations()` returns a `Future` that is true if a refresh has been triggered, and false if not. False means either the cache expiration time hasn't expired, there was no change, or another thread is currently checking for a refresh.
94+
You can also use *curl* to test your application, for example:
95+
96+
```cmd
97+
curl -X GET http://localhost:8080/
98+
```
99+
100+
1. To test dynamic configuration, open the Azure App Configuration portal associated with your application. Select **Configuration Explorer**, and update the value of your displayed key, for example:
101+
102+
| Key | Value |
103+
|---|---|
104+
| /application/config.message | Hello - Updated |
105+
106+
1. Update the sentinel key you created earlier to a new value. This change will trigger the application to refresh all configuration keys once the refresh interval has passed.
107+
108+
| Key | Value |
109+
|---|---|
110+
| sentinel | 2 |
111+
112+
1. Refresh the browser page twice to see the new message displayed. The first time triggers the refresh, the second loads the changes.
113+
114+
> [!NOTE]
115+
> The library only checks for changes on the after the refresh interval has passed, if the period hasn't passed then no change will be seen, you will have to wait for the period to pass then trigger the refresh check.
44116
45117
## Use automated refresh
46118
@@ -54,7 +126,7 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `azu
54126
<dependency>
55127
<groupId>com.azure.spring</groupId>
56128
<artifactId>azure-spring-cloud-appconfiguration-config-web</artifactId>
57-
<version>2.0.0</version>
129+
<version>2.6.0</version>
58130
</dependency>
59131
```
60132
@@ -65,6 +137,7 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `azu
65137
66138
```properties
67139
spring.cloud.azure.appconfiguration.stores[0].monitoring.enabled=true
140+
spring.cloud.azure.appconfiguration.stores[0].monitoring.refresh-interval= 30s
68141
spring.cloud.azure.appconfiguration.stores[0].monitoring.triggers[0].key=sentinel
69142
```
70143
@@ -105,11 +178,14 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `azu
105178
|---|---|
106179
| sentinel | 2 |
107180
108-
1. Refresh the browser page to see the new message displayed.
181+
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.
182+
183+
> [!NOTE]
184+
> The library only checks for changes on after the refresh interval has passed. If the refresh interval hasn't passed then it will not check for changes, you will have to wait for the interval to pass then trigger the refresh check.
109185

110186
## Next steps
111187

112-
In this tutorial, you enabled your Spring Boot app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
188+
In this tutorial, you enabled your Spring Boot app to dynamically refresh configuration settings from App Configuration. For further questions see the [reference documentation](https://go.microsoft.com/fwlink/?linkid=2180917), it has all of the details on how the Spring Cloud Azure App Configuration library works. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
113189

114190
> [!div class="nextstepaction"]
115191
> [Managed identity integration](./howto-integrate-azure-managed-service-identity.md)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ms.service: azure-app-configuration
1313
ms.workload: tbd
1414
ms.devlang: java
1515
ms.topic: tutorial
16-
ms.date: 04/05/2021
16+
ms.date: 05/02/2022
1717
ms.author: mametcal
1818

1919
#Customer intent: I want to use push refresh to dynamically update my app to use the latest configuration data in App Configuration.
@@ -41,7 +41,7 @@ In this tutorial, you learn how to:
4141
## Prerequisites
4242

4343
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
44-
- A supported [Java Development Kit (JDK)](/java/azure/jdk) with version 8.
44+
- A supported [Java Development Kit (JDK)](/java/azure/jdk) with version 11.
4545
- [Apache Maven](https://maven.apache.org/download.cgi) version 3.0 or above.
4646
- An existing Azure App Configuration Store.
4747

@@ -55,7 +55,7 @@ In this tutorial, you learn how to:
5555
<dependency>
5656
<groupId>com.azure.spring</groupId>
5757
<artifactId>azure-spring-cloud-appconfiguration-config-web</artifactId>
58-
<version>2.0.0</version>
58+
<version>2.6.0</version>
5959
</dependency>
6060

6161
<!-- Adds the Ability to Push Refresh -->
@@ -65,7 +65,7 @@ In this tutorial, you learn how to:
6565
</dependency>
6666
```
6767

68-
1. Setup [Maven App Service Deployment](../app-service/quickstart-java.md?tabs=javase) so the application can be deployed to Azure App Service via Maven.
68+
1. Set up [Maven App Service Deployment](../app-service/quickstart-java.md?tabs=javase) so the application can be deployed to Azure App Service via Maven.
6969

7070
```console
7171
mvn com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config
@@ -144,7 +144,7 @@ Event Grid Web Hooks require validation on creation. You can validate by followi
144144
145145
1. Click on `Create` to create the event subscription. When `Create` is selected a registration request for the Web Hook will be sent to your application. This is received by the Azure App Configuration client library, verified, and returns a valid response.
146146
147-
1. Click on `Event Subscriptions` in the `Events` pane to validated that the subscription was created successfully.
147+
1. Click on `Event Subscriptions` in the `Events` pane to validate that the subscription was created successfully.
148148
149149
:::image type="content" source="./media/event-subscription-view-webhook.png" alt-text="Web Hook shows up in a table on the bottom of the page." :::
150150
@@ -173,7 +173,7 @@ Event Grid Web Hooks require validation on creation. You can validate by followi
173173
174174
## Next steps
175175
176-
In this tutorial, you enabled your Java app to dynamically refresh configuration settings from App Configuration. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
176+
In this tutorial, you enabled your Java app to dynamically refresh configuration settings from App Configuration. For further questions see the [reference documentation](https://go.microsoft.com/fwlink/?linkid=2180917), it has all of the details on how the Spring Cloud Azure App Configuration library works. To learn how to use an Azure managed identity to streamline the access to App Configuration, continue to the next tutorial.
177177
178178
> [!div class="nextstepaction"]
179179
> [Managed identity integration](./howto-integrate-azure-managed-service-identity.md)

articles/azure-app-configuration/howto-convert-to-the-new-spring-boot.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.devlang: java
77
author: mrm9084
88
ms.author: mametcal
99
ms.topic: how-to
10-
ms.date: 07/08/2021
10+
ms.date: 05/02/2022
1111
---
1212

1313
# Convert to new App Configuration Spring Boot library
@@ -29,12 +29,12 @@ All of the Azure Spring Boot libraries have had their Group and Artifact IDs upd
2929
<dependency>
3030
<groupId>com.azure.spring</groupId>
3131
<artifactId>azure-spring-cloud-appconfiguration-config</artifactId>
32-
<version>2.0.0-beta.2</version>
32+
<version>2.6.0</version>
3333
</dependency>
3434
<dependency>
3535
<groupId>com.azure.spring</groupId>
3636
<artifactId>azure-spring-cloud-appconfiguration-config-web</artifactId>
37-
<version>2.0.0-beta.2</version>
37+
<version>2.6.0</version>
3838
</dependency>
3939
```
4040

@@ -61,7 +61,7 @@ az appconfig kv import -n your-stores-name -s file --format properties --label d
6161

6262
or use the Import/Export feature in the portal.
6363

64-
When you are completely moved to the new version, you can removed the old keys by running:
64+
When you are completely moved to the new version, you can remove the old keys by running:
6565

6666
```azurecli
6767
az appconfig kv delete -n ConversionTest --key /application_dev/*

0 commit comments

Comments
 (0)