Steeltoe Documentation
  • Why Steeltoe
    Overview Microservices Cloud Web Applications Event Driven
  • Get Started
    Steeltoe Initializr Guides Documentation API Browser Blog
  • Projects
    Steeltoe Application Configuration Steeltoe Circuit Breakers Steeltoe Dynamic Logging Steeltoe Management Steeltoe Messaging Steeltoe Network File Shares Steeltoe Security Steeltoe Service Connectors Steeltoe Service Discovery Steeltoe Stream
  • Support
  • Community
Search Results for

    Table of Contents
    . . .

    App Configuration with a Spring Config Server

    This tutorial takes you through setting up a .NET Core application that gets configuration values from a Spring Config Server.

    Note

    For more detailed examples, please refer to the Simple (Config Server) project in the Steeltoe Samples Repository.

    First, create a GitHub repository to hold config values.

    1. Navigate to GitHub and either login or create a new account
    2. Create and initialize a new public repository, named Spring-Config-Demo
    3. Once created, note the url of the new repo

    Next, add a config file to the repository.

    1. Create a new file in the repo named my-values.yml

    2. Add the following to the file

      Value1: some-val
      Value2: another-val
      
    3. Commit the new file to the repo

    Then, start a config server instance using the Steeltoe dockerfile.

    docker run -p 8888:8888 steeltoeoss/config-server --spring.cloud.config.server.git.default-label=main --spring.cloud.config.server.git.uri=<NEW_REPO_URL>
    

    Note: By default, the config server assumes the branch name to be master. The spring.cloud.config.server.git.default-label switch above changes that to main.

    Next, create a .NET Core WebAPI that retrieves values from the Spring Config instance.

    1. Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr

    2. Name the project "SpringConfigExample"

    3. Add the "Spring Cloud Config Server" dependency

    4. Click Generate to download a zip containing the new project

    5. Extract the zipped project and open in your IDE of choice

    6. Set the instance address and name in appsettings.json

      {
        "spring": {
          "application": {
            "name": "my-values"
          }
        }
      }
      
      Note

      For the application to find its values in the git repo, the spring:application:name and the yaml file name must match. In this example my-values matched.

    Run the application

    • .NET cli
    • Visual Studio
    dotnet run <PATH_TO>\SpringConfigExample.csproj
    

    Navigate to the endpoint (you may need to change the port number) http://localhost:5000/api/values

    1. Choose the top Debug menu, then choose Start Debugging (F5). This should bring up a browser with the app running
    2. Navigate to the endpoint (you may need to change the port number) http://localhost:8080/api/values

    Once the app loads you will see the two values output.

    ["some-val","another-val"]

    X
    • Edit this page