Set up a configuration repository

You’ve set up the compute and database services that will host your applications and store your application data. The next step is to set up the application configuration settings that allow your Spring Boot application to connect with the database you just created.

The example Spring Petclinic workload includes a config server that the workload’s various component applications will all use for this purpose. In Azure Container Apps, we can also make use of the built-in config server component, which you will use in one of the following modules.

Step-by-step guidance

Your config server will need to have access to a permanent storage location where your configuration file will live. In this scenario, you can store this file on your Git repo along with the rest of your code, and then set up the config server to know where to find the file.

We’ve provided the configuration file used by the Spring applications in the config folder of this lab’s GitHub repo.

This lab simplifies some of the original spring-petclinic-microservices config settings to make these lab steps easier to execute.

Perform the following steps to get the config server to load the proper file:

  1. Check the content of the config file application-mysql.yml.

    spring:
        datasource:
            url: jdbc:mysql://${SQL_SERVER}.mysql.database.azure.com:3306/petclinic?useSSL=true
            username: ${SQL_USER}
            password: ${SQL_PASSWORD}
        sql:
            init:
                schema-locations: classpath*:db/mysql/schema.sql
                data-locations: classpath*:db/mysql/data.sql
                mode: ALWAYS
    
    • The properties of spring.datasource are used to build connections to the MySQL database.
    • The properties of spring.sql.init set the MySQL database initialization operations.
  2. Store (as environment variables) information about the Git repo where the config file lives:

    GIT_URI="https://github.com/Azure-Samples/java-on-aca.git"
    SEARCH_PATH="config"
    LABEL=main
    

In this part of this lab, we use the public repository for the config server and put placeholder variables in the application.yml config file for the MySQL username and password. In this configuration, you might still need to provide the credentials when you create or update container apps. In an upcoming exercise, you’ll remediate this potential vulnerability by removing clear text credentials from your configuration.