Update the applications to use passwordless connectivity
By now all setup on the spring apps service side is done. You will still need to update your microservices to make use of the new passwordless capabilities. To accomplish this, you can use the following the guidance: Connect an Azure Database for MySQL instance to your application in Azure Spring Apps.
The following three apps of your application use the database hosted by the Azure Database for MySQL Single Server instance, so they will need to have their code updated:
customers-service
vets-service
visits-service
Step by step guidance
-
From the Git Bash window, in the
java-microservices-asa-e-lab
repository you cloned locally, use your favorite text editor to open thepom.xml
files of the customers, visits and vets services (within thesrc/spring-petclinic-customers-service
,src/spring-petclinic-visits-service
, andsrc/spring-petclinic-vets-service
directories). For each, replace themysql-connector-j
dependency (within the<dependencies>...</dependencies>
section) with thespring-cloud-azure-starter-jdbc-mysql
dependency and save the file:<!-- Replace this dependency --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency>
<!-- by this dependency --> <dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId> </dependency>
-
Rebuild the microservices by running the below command in the git bash window:
cd ~/workspaces/java-microservices-asa-e-lab/src mvn clean package -DskipTests
-
Verify that the build succeeds by reviewing the output of the
mvn clean package -DskipTests
command, which should have the following format:[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for spring-petclinic-microservices 3.0.2: [INFO] [INFO] spring-petclinic-microservices ..................... SUCCESS [ 0.249 s] [INFO] spring-petclinic-admin-server ...................... SUCCESS [ 16.123 s] [INFO] spring-petclinic-customers-service ................. SUCCESS [ 6.749 s] [INFO] spring-petclinic-vets-service ...................... SUCCESS [ 4.845 s] [INFO] spring-petclinic-visits-service .................... SUCCESS [ 5.063 s] [INFO] spring-petclinic-config-server ..................... SUCCESS [ 1.777 s] [INFO] spring-petclinic-discovery-server .................. SUCCESS [ 2.563 s] [INFO] spring-petclinic-api-gateway ....................... SUCCESS [ 15.582 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 55.901 s [INFO] Finished at: 2023-06-02T14:07:49Z [INFO] ------------------------------------------------------------------------
-
Once the build is complete, redeploy each of the apps.
az spring app deploy --name ${CUSTOMERS_SERVICE} \ --config-file-patterns ${CUSTOMERS_SERVICE} \ --artifact-path ${CUSTOMERS_SERVICE_JAR} az spring app deploy --name ${VETS_SERVICE} \ --config-file-patterns ${VETS_SERVICE} \ --artifact-path ${VETS_SERVICE_JAR} az spring app deploy --name ${VISITS_SERVICE} \ --config-file-patterns ${VISITS_SERVICE} \ --artifact-path ${VISITS_SERVICE_JAR}
-
Retest your application through its public endpoint. Ensure that the application is functional, while the connection string secrets are retrieved from Azure Key Vault.
-
In case you don’t see data in your application, take a look at the
customers-service
logs to make sure the configuration gets picked up correctly and there are no errors on startup.az spring app logs --name ${CUSTOMERS_SERVICE} --follow
In case you see no errors, you can escape out of the log statement with
Ctrl+C
and you can proceed with the next steps. In case you see errors, review the steps you executed and retry. The LabTips file also contains steps on how to recover from errors.