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.
First, create a Github repository to hold config values.
- Navigate to Github and either login or create a new account
- Create and initialize a new repository, named
Spring-Config-Demo
- Once created note the url of the new repo
Next, add a config file to the repository.
- Create a new file in the repo named
my-values.yml
-
Add the following to the file
Value1: some-val Value2: another-val
- Commit the new file to the repo
Then, start a config server instance. Depending on your hosting platform this is done in several ways.
Next, create a .NET Core WebAPI that retrieves values from the Spring Config instance
- Create a new ASP.NET Core WebAPI app with the Steeltoe Initializr
- SteeltoeVersion: 2.4 for the latest stable
- Project Metadata:Name: Spring_Config_ExampleTarget Framework: netcoreapp3.1 is the latest stable
- Dependencies: Config Server
- Click Generate Project to download a zip containing the new project
- Extract the zipped project and open in your IDE of choice (we use Visual Studio)
-
Set the instance address and name in appsettings.json
noteFor 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
-
Once the app loads in the browser you will see the two values output.
["some-val","another-val"]