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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/enable-dynamic-configuration-java-spring-app.md
+94-18Lines changed: 94 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,40 +7,112 @@ author: mrm9084
7
7
ms.service: azure-app-configuration
8
8
ms.devlang: java
9
9
ms.topic: tutorial
10
-
ms.date: 12/09/2020
10
+
ms.date: 05/02/2022
11
11
ms.custom: devx-track-java
12
12
ms.author: mametcal
13
13
14
14
#Customer intent: As a Java Spring developer, I want to dynamically update my app to use the latest configuration data in App Configuration.
15
15
---
16
16
# Tutorial: Use dynamic configuration in a Java Spring app
17
17
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.
19
19
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.
21
22
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.
23
28
24
29
## Use manual refresh
25
30
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
+
26
33
App Configuration exposes `AppConfigurationRefresh` which can be used to check if the cache is expired and if it is expired trigger a refresh.
`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.
1.Open the **AzurePortal** and navigate to your AppConfiguration resource associated with your application. Select**ConfigurationExplorer** 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.
42
93
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.
44
116
45
117
## Use automated refresh
46
118
@@ -54,7 +126,7 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `azu
@@ -105,11 +178,14 @@ Then, open the *pom.xml* file in a text editor and add a `<dependency>` for `azu
105
178
|---|---|
106
179
| sentinel | 2 |
107
180
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.
109
185
110
186
## Next steps
111
187
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
+
Inthis tutorial, you enabled your SpringBoot app to dynamically refresh configuration settings from AppConfiguration. 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.
@@ -65,7 +65,7 @@ In this tutorial, you learn how to:
65
65
</dependency>
66
66
```
67
67
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.
@@ -144,7 +144,7 @@ Event Grid Web Hooks require validation on creation. You can validate by followi
144
144
145
145
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.
146
146
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.
148
148
149
149
:::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." :::
150
150
@@ -173,7 +173,7 @@ Event Grid Web Hooks require validation on creation. You can validate by followi
173
173
174
174
## Next steps
175
175
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.
0 commit comments