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
-
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>
-
Now you’ll need to update the POM files for the
spring-petclinic-customers-service
,spring-petclinic-visits-service
andspring-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 themysql-connector-j
artifact with this one:<dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId> </dependency>
-
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
-
Rebuild the projects:
mvn clean package -DskipTests