page_type | languages | products | name | description | ||
---|---|---|---|---|---|---|
sample |
|
|
Managing Features and Get Configurations From App Configuration in Spring Boot Application |
This sample demonstrates how to manage features and how to get configurations from App Configuration to Spring Environment in Spring Boot application. |
This sample describes how to use spring-cloud-azure-feature-management to manage features and how to get configurations from App Configuration Service to Spring Environment.
spring-cloud-azure-feature-management
doesn't require use of the App Configuration service, but can be integrated with it. The next section shows how to use the library without the App Configuration service, the section after shows how to update the example to use it with the App Configuration service.
Start the application and check the resulting console output to check the returned value.
- Load features from application.yml
mvn spring-boot:run
- Check the returned value. The feature
Beta
has one filterRandom
which defines the Beta feature will be activated randomly with some chance value. You should see the following information displayed: RUNNING : application or RUNNING : beta.
- Create a Configuration Store if not exist.
az appconfig create --resource-group <your-resource-group> --name <name-of-your-new-store> --sku Standard
- Import the data file src/main/resources/data/sample-data.json into the Configuration Store created above. Under
For language
selectOther
. UnderFile type
selectYaml
or using the azure cli:
az appconfig kv import -n <name-of-your-new-store> -s file --path <location-of-your-properties-file> --format properties --prefix /application/
It will have you confirm the feature flag before loading it.
- Add the spring-cloud-azure-appconfiguration-config dependency,
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-appconfiguration-config</artifactId>
<version>4.19.0</version>
</dependency>
- Create a file named bootstrap.properties in the resources folder and add the connection string to it.
spring.cloud.azure.appconfiguration.stores[0].connection-string= <your-connection-string>
Note: You can get your connection string from the portal from Access Keys or using the cli:
az appconfig credential list --resource-group <your-resource-group> --name <name-of-your-new-store>
- Delete application.yml.
- Load features from application.yml
mvn spring-boot:run
- Check the returned value. The feature
Beta
has one filterRandom
which defines the Beta feature will be activated randomly with some chance value. You should see the following information displayed: RUNNING : application or RUNNING : beta.
Please refer to this README about more usage details.
Now that you have the Spring Boot application running locally, it's time to move it to production. Azure Spring Apps 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.