Quickstart: Create a Java Spring app with Azure App Configuration

In this quickstart, you incorporate Azure App Configuration into a Java Spring app to centralize storage and management of application settings separate from your code.


Create an App Configuration store

  1. To create a new App Configuration store, sign in to the Azure portal.

  2. In the upper-left corner of the home page, select Create a resource.

  3. In the Search services and marketplace box, enter App Configuration and select Enter.

    Screenshot that shows the Search for App Configuration page.

  4. Select App Configuration from the search results, and then select Create.

    Screenshot that shows the Create page.

  5. On the Create App Configuration pane, enter the following settings:

    Setting Suggested value Description
    Subscription Your subscription Select the Azure subscription that you want to use to test App Configuration. If your account has only one subscription, it's automatically selected and the Subscription list isn't displayed.
    Resource group AppConfigTestResources Select or create a resource group for your App Configuration store resource. This group is useful for organizing multiple resources that you might want to delete at the same time by deleting the resource group. For more information, see Use resource groups to manage your Azure resources.
    Resource name Globally unique name Enter a unique resource name to use for the App Configuration store resource. The name must be a string between 5 and 50 characters and contain only numbers, letters, and the - character. The name can't start or end with the - character.
    Location Central US Use Location to specify the geographic location in which your app configuration store is hosted. For the best performance, create the resource in the same region as other components of your application.
    Pricing tier Free Select the desired pricing tier. For more information, see the App Configuration pricing page.
  6. Select Review + create to validate your settings.

  7. Select Create. The deployment might take a few minutes.

  8. After the deployment finishes, go to the App Configuration resource. Select Settings > Access keys. Make a note of the primary read-only key connection string. You'll use this connection string later to configure your application to communicate with the App Configuration store that you created.

  1. Select Configuration Explorer > + Create > Key-value to add the following key-value pairs:

    Key Value
    /application/config.message Hello

    Leave Label and Content Type empty for now.

  2. Select Apply.

Create a Spring Boot app

To create a new Spring Boot project:

  1. Browse to the Spring Initializr.

  2. Specify the following options:

    • Generate a Maven project with Java.
    • Specify a Spring Boot version that's equal to or greater than 2.0.
    • Specify the Group and Artifact names for your application.
    • Add the Spring Web dependency.
  3. After you specify the previous options, select Generate Project. When prompted, download the project to a path on your local computer.

Connect to an App Configuration store

  1. After you extract the files on your local system, your simple Spring Boot application is ready for editing. Locate the pom.xml file in the root directory of your app.

  2. Open the pom.xml file in a text editor, and add the Spring Cloud Azure Config starter to the list of <dependencies>:

    Spring Boot 2.6



    If you need to support an older version of Spring Boot see our old library.

  3. Create a new Java file named MessageProperties.java in the package directory of your app. Add the following lines:

    package com.example.demo;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    @ConfigurationProperties(prefix = "config")
    public class MessageProperties {
        private String message;
        public String getMessage() {
            return message;
        public void setMessage(String message) {
            this.message = message;
  4. Create a new Java file named HelloController.java in the package directory of your app. Add the following lines:

    package com.example.demo;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    public class HelloController {
        private final MessageProperties properties;
        public HelloController(MessageProperties properties) {
            this.properties = properties;
        public String getMessage() {
            return "Message: " + properties.getMessage();
  5. Open the main application Java file, and add @EnableConfigurationProperties to enable this feature.

    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    public class DemoApplication {
        public static void main(String[] args) {
            SpringApplication.run(DemoApplication.class, args);
  6. Open the auto-generated unit test and update to disable Azure App Configuration, or it will try to load from the service when runnings unit tests.

    package com.example.demo;
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    @SpringBootTest(properties = "spring.cloud.azure.appconfiguration.enabled=false")
    class DemoApplicationTests {
        void contextLoads() {
  7. Create a new file named bootstrap.properties under the resources directory of your app, and add the following line to the file.

    spring.cloud.azure.appconfiguration.stores[0].connection-string= ${APP_CONFIGURATION_CONNECTION_STRING}
  8. Set an environment variable named APP_CONFIGURATION_CONNECTION_STRING, and set it to the access key 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:

    setx APP_CONFIGURATION_CONNECTION_STRING "connection-string-of-your-app-configuration-store"

    If you use Windows PowerShell, run the following command:

    $Env:APP_CONFIGURATION_CONNECTION_STRING = "connection-string-of-your-app-configuration-store"

    If you use macOS or Linux, run the following command:

    export APP_CONFIGURATION_CONNECTION_STRING='connection-string-of-your-app-configuration-store'

Build and run the app locally

  1. Open command prompt to the root directory and run the following commands to build your Spring Boot application with Maven and run it.

    mvn clean package
    mvn spring-boot:run
  2. After your application is running, use curl to test your application, for example:

    curl -X GET http://localhost:8080/

    You see the message that you entered in the App Configuration store.

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.


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.

  1. Sign in to the Azure portal, and select Resource groups.
  2. In the Filter by name box, enter the name of your resource group.
  3. In the result list, select the resource group name to see an overview.
  4. Select Delete resource group.
  5. 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 with a Java Spring app. For more information, see Spring on Azure. For further questions see the reference documentation, it has all of the details on how the Spring Cloud Azure App Configuration library works. To learn how to enable your Java Spring app to dynamically refresh configuration settings, continue to the next tutorial.