Update the applications to use passwordless connectivity
By now all setup on the container apps side is done. You will still need to update your microservices to make use of the new passwordless capabilities.
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
-
You will now need to update the
spring-petclinic-customers-service
,spring-petclinic-visits-service
andspring-petclinic-vets-service
to make use of the passwordless capabilities of the Azure SDK. In eachpom.xml
file of each microservice replace themysql-connector-j
artifact by this one:<dependency> <groupId>com.azure.spring</groupId> <artifactId>spring-cloud-azure-starter-jdbc-mysql</artifactId> </dependency>
-
In the main
pom.xml
file add the Azure BOM 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>
-
In the same file also add an additional property between the
<properties></properties>
element for the Azure Spring Cloud version we are going to use.<version.spring.cloud.azure>5.13.0</version.spring.cloud.azure>
-
With these changes done. Make sure you are in the /src folder and rebuild the project.
cd /workspaces/java-microservices-aca-lab/src mvn clean package -DskipTests
-
In the config repository there will be no credentials, you may use the config files saved in this repository, under directory config. Update config server configuration:
URI=https://github.com/Azure-Samples/java-microservices-aca-lab LABEL=main SEARCH_PATH=config az containerapp env java-component config-server-for-spring update \ --environment $ACA_ENVIRONMENT \ --resource-group $RESOURCE_GROUP \ --name $JAVA_CONFIG_COMP_NAME \ --configuration spring.cloud.config.server.git.uri=$URI spring.cloud.config.server.git.default-label=$LABEL spring.cloud.config.server.git.search-paths=$SEARCH_PATH
-
Once the build is done, move to the
staging-acr
directory and recreate the containers for customers, visits and vets.cd staging-acr export APP_NAME="customers-service" cp ../spring-petclinic-$APP_NAME/target/spring-petclinic-$APP_NAME-$VERSION.jar spring-petclinic-$APP_NAME-$VERSION.jar sed -i "s|my-service|$APP_NAME|g" Dockerfile az containerapp update \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --source . \ --set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "customers-service"}}' InstrumentationKey=$AI_CONNECTIONSTRING sed -i "s|$APP_NAME|my-service|g" Dockerfile rm spring-petclinic-$APP_NAME-$VERSION.jar export APP_NAME="vets-service" cp ../spring-petclinic-$APP_NAME/target/spring-petclinic-$APP_NAME-$VERSION.jar spring-petclinic-$APP_NAME-$VERSION.jar sed -i "s|my-service|$APP_NAME|g" Dockerfile az containerapp update \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --source . \ --set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "vets-service"}}' InstrumentationKey=$AI_CONNECTIONSTRING sed -i "s|$APP_NAME|my-service|g" Dockerfile rm spring-petclinic-$APP_NAME-$VERSION.jar export APP_NAME="visits-service" cp ../spring-petclinic-$APP_NAME/target/spring-petclinic-$APP_NAME-$VERSION.jar spring-petclinic-$APP_NAME-$VERSION.jar sed -i "s|my-service|$APP_NAME|g" Dockerfile az containerapp update \ --name $APP_NAME \ --resource-group $RESOURCE_GROUP \ --source . \ --set-env-vars APPLICATIONINSIGHTS_CONNECTION_STRING=$AI_CONNECTIONSTRING APPLICATIONINSIGHTS_CONFIGURATION_CONTENT='{"role": {"name": "visits-service"}}' InstrumentationKey=$AI_CONNECTIONSTRING sed -i "s|$APP_NAME|my-service|g" Dockerfile rm spring-petclinic-$APP_NAME-$VERSION.jar
-
This will redeploy each of your apps. After redeploy, double check that yu are still able to connect to the database and see data in the apps. If that is not the case, use the logs to troubleshoot.