Update application configuration to use passwordless connectivity

Now, with the database configured, you’ll set up your applications to use a passwordless connection. This doesn’t require any changes to your app code, but you do need to include the Azure Service Connector in your application containers, as well as some additional Java dependencies. To make these updates, you’ll simply modify your application configurations and rebuild your apps.

These are the three applications that communicate with your database, so you’ll need to update their container configurations:

  • customers-service
  • vets-service
  • visits-service

Step-by-step guidance

  1. Update the main POM file.

    In the main pom.xml file, add another property between the <properties></properties> element for the Azure Spring Cloud version that we’re going to use:

    <version.spring.cloud.azure>5.18.0</version.spring.cloud.azure>
    

    In the same file, add the Azure Spring BOM (Bill of Materials) as an extra dependency between the <dependencyManagement><dependencies></dependencies></dependencyManagement> elements:

        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-dependencies</artifactId>
            <version>${version.spring.cloud.azure}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    
  2. Now you’ll need to update the POM files for the spring-petclinic-customers-service, spring-petclinic-visits-service and spring-petclinic-vets-service projects to make use of the managed identity capabilities of the Azure SDK.

    In the pom.xml file for each of these applications, replace the mysql-connector-j artifact with this one:

        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId>
        </dependency>
    
  3. Next, you’ll want to modify the associated SQL schemas to ensure you’ve removed any unnecessary user access. You can do this by opening them and removing the line GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc';.

    To update the schema files at once, run the following commands:

    sed -i '/GRANT ALL PRIVILEGES ON/d' spring-petclinic-customers-service/src/main/resources/db/mysql/schema.sql
    sed -i '/GRANT ALL PRIVILEGES ON/d' spring-petclinic-vets-service/src/main/resources/db/mysql/schema.sql
    sed -i '/GRANT ALL PRIVILEGES ON/d' spring-petclinic-visits-service/src/main/resources/db/mysql/schema.sql
    
  4. Rebuild the projects:

    mvn clean package -DskipTests