|
| 1 | +--- |
| 2 | +page_type: sample |
| 3 | +languages: |
| 4 | +- java |
| 5 | +products: |
| 6 | +- azure-app-configuration |
| 7 | +name: Refreshing Configuration Properties From App Configuration in Spring Boot Application using Entra ID |
| 8 | +description: This sample demonstrates how to refresh configuration properties from App Configuration in Spring Boot application using Entra ID. |
| 9 | +--- |
| 10 | + |
| 11 | +# Refreshing Configuration Properties From App Configuration in Spring Boot Application |
| 12 | + |
| 13 | +## Prerequisite |
| 14 | + |
| 15 | +* A [Java Development Kit (JDK)](https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable), version 8. |
| 16 | +* [Apache Maven](http://maven.apache.org/), version 3.0 or later. |
| 17 | + |
| 18 | +## How to run |
| 19 | + |
| 20 | +### Setup your App Configuration Store |
| 21 | + |
| 22 | +1. To create your Azure App Configuration store, you can use: |
| 23 | + |
| 24 | + ```azurecli |
| 25 | + az appconfig create --resource-group <your-resource-group> --name <name-of-your-new-store> --sku Standard |
| 26 | + ``` |
| 27 | +
|
| 28 | +1. Create the test key in your new store: |
| 29 | +
|
| 30 | + ```azurecli |
| 31 | + az appconfig kv set --key /application/config.message --value testKey --name <name-of-your-new-store> --yes |
| 32 | + ``` |
| 33 | +
|
| 34 | +1. Create monitor trigger. |
| 35 | +
|
| 36 | + ```azurecli |
| 37 | + az appconfig kv set --key sentinel --value 1 --name <name-of-your-new-store> --yes |
| 38 | + ``` |
| 39 | +
|
| 40 | +This value should match the `spring.cloud.azure.appconfiguration.stores[0].monitoring.triggers[0].key` value in `bootstrap.properties`. |
| 41 | +
|
| 42 | +### Setup your environment |
| 43 | +
|
| 44 | +1. Set an environment variable named **APP_CONFIGURATION_ENDPOINT**, and set it to the endpoint to your App Configuration store. At the command line, run the following command and restart the command prompt to allow the change to take effect: |
| 45 | +
|
| 46 | + ```cmd |
| 47 | + setx APP_CONFIGURATION_ENDPOINT "endpoint-of-your-app-configuration-store" |
| 48 | + ``` |
| 49 | + |
| 50 | + If you use Windows PowerShell, run the following command: |
| 51 | + |
| 52 | + ```azurepowershell |
| 53 | + $Env:APP_CONFIGURATION_ENDPOINT = "endpoint-of-your-app-configuration-store" |
| 54 | + ``` |
| 55 | + |
| 56 | + If you use macOS or Linux, run the following command: |
| 57 | + |
| 58 | + ```cmd |
| 59 | + export APP_CONFIGURATION_ENDPOINT='endpoint-of-your-app-configuration-store' |
| 60 | + ``` |
| 61 | + |
| 62 | +### Run the application |
| 63 | + |
| 64 | +1. Build the application |
| 65 | + |
| 66 | + ```console |
| 67 | + mvn clean package |
| 68 | + ``` |
| 69 | + |
| 70 | +1. Run the application |
| 71 | + |
| 72 | + ```console |
| 73 | + mvn spring-boot:run |
| 74 | + ``` |
| 75 | + |
| 76 | +1. Go to `localhost:8080` which will display the value `testKey`. |
| 77 | + |
| 78 | +1. Update key to new value. |
| 79 | + |
| 80 | + ```azurecli |
| 81 | + az appconfig kv set --key /application/config.message --value updatedTestKey --name <name-of-your-new-store> --yes |
| 82 | + ``` |
| 83 | + |
| 84 | +1. Update monitor trigger, to trigger refresh. |
| 85 | + |
| 86 | + ```azurecli |
| 87 | + az appconfig kv set --key sentinel --value 2 --name <name-of-your-new-store> --yes |
| 88 | + ``` |
| 89 | + |
| 90 | +1. Refresh page, this will trigger the refresh update. |
| 91 | + |
| 92 | +1. After a couple seconds refresh again, this time the new value `updatedTestKey` will show. |
| 93 | + |
| 94 | +## Deploy to Azure Spring Apps |
| 95 | + |
| 96 | +Now that you have the Spring Boot application running locally, it's time to move it to production. [Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/overview) makes it easy to deploy Spring Boot applications to Azure without any code changes. The service manages the infrastructure of Spring applications so developers can focus on their code. Azure Spring Apps provides lifecycle management using comprehensive monitoring and diagnostics, configuration management, service discovery, CI/CD integration, blue-green deployments, and more. To deploy your application to Azure Spring Apps, see [Deploy your first application to Azure Spring Apps](https://learn.microsoft.com/azure/spring-apps/quickstart?tabs=Azure-CLI). |
0 commit comments