Merk
Tilgang til denne siden krever autorisasjon. Du kan prøve å logge på eller endre kataloger.
Tilgang til denne siden krever autorisasjon. Du kan prøve å endre kataloger.
In this quickstart, you'll create a feature flag in Azure App Configuration and use it to dynamically control Spring Boot apps to create an end-to-end implementation of feature management.
The Spring Boot Feature Management libraries do not have a dependency on any Azure libraries. They seamlessly integrate with App Configuration through its Spring Boot configuration provider.
Prerequisites
- An Azure account with an active subscription. Create one for free.
- An App Configuration store, as shown in the tutorial for creating a store.
- A supported Java Development Kit SDK with version 17.
- Apache Maven version 3.0 or above.
Add a feature flag
Add a feature flag called Beta to the App Configuration store and leave Label and Description with their default values. For more information about how to add feature flags to a store using the Azure portal or the CLI, go to Create a feature flag. At this stage the Enable feature flag check box should be unchecked.

Create a console app
Create a new Spring Boot project:
Browse to the Spring Initializr.
Specify the following options:
- Generate a Maven project with Java.
- Specify a Spring Boot version that's equal to or greater than 3.0.
- Specify the Group and Artifact names for your application. This article uses
com.exampleanddemo.
After you specify the previous options, select Generate Project. Download and extract the project to your local computer.
Locate pom.xml in the root directory of your app and open it in a text editor.
Add the following to the list of
<dependencies>:<dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-appconfiguration-config</artifactId> </dependency> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-feature-management</artifactId> </dependency>Add the following
<dependencyManagement>section to manage the Spring Cloud Azure library versions:<dependencyManagement> <dependencies> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-dependencies</artifactId> <version>7.2.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>Navigate to the
resourcesdirectory of your app and open theapplication.propertiesorapplication.yamlfile.You use the
DefaultAzureCredentialto authenticate to your App Configuration store. For authorization to work, you need to grant the App Configuration Data Reader role to the credential that your app uses. For instructions, see Authentication with token credentials.Be sure to allow sufficient time for the permission to propagate before running your application.spring.config.import=azureAppConfiguration spring.cloud.azure.appconfiguration.stores[0].endpoint= ${AZURE_APPCONFIG_ENDPOINT} spring.cloud.azure.appconfiguration.stores[0].feature-flags.enabled=trueUpdate the
DemoApplication.javafile in the package directory of your app with the following code:import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import com.azure.spring.cloud.feature.management.FeatureManager; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public CommandLineRunner runner(FeatureManager featureManager) { return args -> { System.out.println("Beta is enabled: " + featureManager.isEnabled("Beta")); }; } }Set an environment variable named AZURE_APPCONFIG_ENDPOINT, and set it to the endpoint of your App Configuration store. At the command line, run the following command and restart the command prompt to allow the change to take effect:
setx AZURE_APPCONFIG_ENDPOINT "<endpoint-of-your-app-configuration-store>"Restart the command prompt to allow the change to take effect. Validate that it's set properly by printing the value of the environment variable.
Build and run your Spring Boot application with Maven.
mvn clean package mvn spring-boot:runIn the App Configuration portal select Feature Manager, and change the state of the Beta feature flag to On, using the toggle in the Enabled column.
Key State Beta On Restart the application. The application will print the following:
Beta is enabled: true
Clean up resources
If you don't want to continue using the resources created in this article, delete the resource group you created here to avoid charges.
Important
Deleting a resource group is irreversible. The resource group and all the resources in it are permanently deleted. Ensure that you don't accidentally delete the wrong resource group or resources. If you created the resources for this article inside a resource group that contains other resources you want to keep, delete each resource individually from its respective pane instead of deleting the resource group.
- Sign in to the Azure portal, and select Resource groups.
- In the Filter by name box, enter the name of your resource group.
- In the result list, select the resource group name to see an overview.
- Select Delete resource group.
- You're asked to confirm the deletion of the resource group. Enter the name of your resource group to confirm, and select Delete.
After a few moments, the resource group and all its resources are deleted.
Next steps
In this quickstart, you created a new App Configuration store and used it to manage features in a Spring Boot app via the Feature Management libraries.
- Learn more about feature management.
- Manage feature flags.