diff --git a/README.md b/README.md index dba91658fe..485cb88f0a 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,18 @@ page_type: sample languages: - java products: -- Azure Spring Cloud -description: "Deploy Spring Boot apps using Azure Spring Cloud and MySQL" +- Azure Spring Apps +description: "Deploy Spring Boot apps using Azure Spring Apps and MySQL" urlFragment: "spring-petclinic-microservices" --- -# Deploy Spring Boot apps using Azure Spring Cloud and MySQL +# Deploy Spring Boot apps using Azure Spring Apps and MySQL -Azure Spring Cloud enables you to easily run a Spring Boot applications on Azure. +Azure Spring Apps enables you to easily run a Spring Boot applications on Azure. -This quickstart shows you how to deploy an existing Java Spring Cloud application to Azure. When -you're finished, you can continue to manage the application via the Azure CLI or switch to using the -Azure Portal. +This quickstart shows you how to deploy an existing Java Spring Cloud application to Azure. When you're finished, you can continue to manage the application via the Azure CLI or switch to using the Azure Portal. -* [Deploy Spring Boot apps using Azure Spring Cloud and MySQL](#deploy-spring-boot-apps-using-azure-spring-cloud-and-mysql) +* [Deploy Spring Boot apps using Azure Spring Apps and MySQL](#deploy-spring-boot-apps-using-azure-spring-cloud-and-mysql) * [What will you experience](#what-will-you-experience) * [What you will need](#what-you-will-need) * [Install the Azure CLI extension](#install-the-azure-cli-extension) @@ -29,9 +27,9 @@ Azure Portal. ## What will you experience You will: - Build existing Spring Boot applications -- Provision an Azure Spring Cloud service instance. If you prefer Terraform, you may also provision using Terraform, see [`README-terraform`](./terraform/README-terraform.md) +- Provision an Azure Spring Apps service instance. If you prefer Terraform, you may also provision using Terraform, see [`README-terraform`](./terraform/README-terraform.md) - Deploy applications to Azure -- Bind applications to Azure Database for MySQL +- Connect applications to Azure Database for MySQL using Azure AD authentication - Open the application - Monitor applications - Automate deployments using GitHub Actions @@ -39,32 +37,19 @@ You will: ## What you will need -In order to deploy a Java app to cloud, you need -an Azure subscription. If you do not already have an Azure -subscription, you can activate your -[MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/) -or sign up for a -[free Azure account]((https://azure.microsoft.com/free/)). +In order to deploy a Java app to cloud, you need an Azure subscription. If you do not already have an Azure subscription, you can activate your [MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/) or sign up for a [free Azure account]((https://azure.microsoft.com/free/)). In addition, you will need the following: -| [Azure CLI version 2.17.1 or higher](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) -| [Java 8](https://www.azul.com/downloads/azure-only/zulu/?version=java-8-lts&architecture=x86-64-bit&package=jdk) +| [Azure CLI version 2.44.0 or higher](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) +| [Java 8](https://adoptium.net/temurin/releases/?version=8) | [Maven](https://maven.apache.org/download.cgi) -| [MySQL CLI](https://dev.mysql.com/downloads/shell/) | [Git](https://git-scm.com/) -| [`jq` utility](https://stedolan.github.io/jq/download/) | -Note - The [`jq` utility](https://stedolan.github.io/jq/download/). On Windows, download [this Windows port of JQ](https://github.com/stedolan/jq/releases) and add the following to the `~/.bashrc` file: - ```bash - alias jq=/jq-win64.exe - ``` - -Note - The Bash shell. While Azure CLI should behave identically on all environments, shell +> Note - The Bash shell. While Azure CLI should behave identically on all environments, shell semantics vary. Therefore, only bash can be used with the commands in this repo. To complete these repo steps on Windows, use Git Bash that accompanies the Windows distribution of -Git. Use only Git Bash to complete this training on Windows. Do not use WSL. ### OR Use Azure Cloud Shell @@ -87,17 +72,15 @@ To run the code in this article in Azure Cloud Shell: ## Install the Azure CLI extension -Install the Azure Spring Cloud extension for the Azure CLI using the following command +Install the Azure Spring extension for the Azure CLI using the following command ```bash - az extension add --name spring-cloud + az extension add --name spring ``` -Note - `spring-cloud` CLI extension `2.1.0` or later is a pre-requisite to enable the -latest Java in-process agent for Application Insights. If you already -have the CLI extension, you may need to upgrade to the latest using -- +Note - `spring` CLI extension `1.5.0` or later is a pre-requisite to enable the latest Java in-process agent for Application Insights. If you already have the CLI extension, you may need to upgrade to the latest using -- ```bash - az extension update --name spring-cloud + az extension update --name spring ``` ## Clone and build the repo @@ -130,7 +113,6 @@ Create a bash script with environment variables by making a copy of the supplied Open `.scripts/setup-env-variables-azure.sh` and enter the following information: ```bash - export SUBSCRIPTION=subscription-id # customize this export RESOURCE_GROUP=resource-group-name # customize this ... @@ -145,12 +127,14 @@ Open `.scripts/setup-env-variables-azure.sh` and enter the following information ``` Then, set the environment: + ```bash source .scripts/setup-env-variables-azure.sh ``` -### Login to Azure -Login to the Azure CLI and choose your active subscription. Be sure to choose the active subscription that is whitelisted for Azure Spring Cloud +### Login to Azure + +Login to the Azure CLI and choose your active subscription. Be sure to choose the active subscription that is whitelisted for Azure Spring Apps ```bash az login @@ -158,20 +142,21 @@ Login to the Azure CLI and choose your active subscription. Be sure to choose th az account set --subscription ${SUBSCRIPTION} ``` -### Create Azure Spring Cloud service instance -Prepare a name for your Azure Spring Cloud service. The name must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number. +### Create Azure Spring App service instance -Create a resource group to contain your Azure Spring Cloud service. +Prepare a name for your Azure Spring App service. The name must be between 4 and 32 characters long and can contain only lowercase letters, numbers, and hyphens. The first character of the service name must be a letter and the last character must be either a letter or a number. + +Create a resource group to contain your Azure Spring App service. ```bash az group create --name ${RESOURCE_GROUP} \ --location ${REGION} ``` -Create an instance of Azure Spring Cloud. +Create an instance of Azure Spring App. ```bash - az spring-cloud create --name ${SPRING_CLOUD_SERVICE} \ + az spring create --name ${SPRING_CLOUD_SERVICE} \ --sku standard \ --sampling-rate 100 \ --resource-group ${RESOURCE_GROUP} \ @@ -186,7 +171,7 @@ Set your default resource group name and cluster name using the following comman az configure --defaults \ group=${RESOURCE_GROUP} \ location=${REGION} \ - spring-cloud=${SPRING_CLOUD_SERVICE} + spring=${SPRING_CLOUD_SERVICE} ``` ### Create and configure Log Analytics Workspace @@ -201,11 +186,15 @@ Create a Log Analytics Workspace using Azure CLI: export LOG_ANALYTICS_RESOURCE_ID=$(az monitor log-analytics workspace show \ --resource-group ${RESOURCE_GROUP} \ - --workspace-name ${LOG_ANALYTICS} | jq -r '.id') + --workspace-name ${LOG_ANALYTICS} \ + --query 'id' \ + --output tsv) - export SPRING_CLOUD_RESOURCE_ID=$(az spring-cloud show \ + export SPRING_CLOUD_RESOURCE_ID=$(az spring show \ --name ${SPRING_CLOUD_SERVICE} \ - --resource-group ${RESOURCE_GROUP} | jq -r '.id') + --resource-group ${RESOURCE_GROUP} \ + --query 'id' \ + --output tsv) ``` Setup diagnostics and publish logs and metrics from Spring Boot apps to Azure Log Analytics: @@ -252,39 +241,39 @@ Setup diagnostics and publish logs and metrics from Spring Boot apps to Azure Lo ]' ``` -### Load Spring Cloud Config Server +### Load Spring Apps Config Server -Use the `application.yml` in the root of this project to load configuration into the Config Server in Azure Spring Cloud. +Use the `application.yml` in the root of this project to load configuration into the Config Server in Azure Spring Apps. ```bash - az spring-cloud config-server set \ + az spring config-server set \ --config-file application.yml \ --name ${SPRING_CLOUD_SERVICE} ``` -### Create applications in Azure Spring Cloud +### Create applications in Azure Spring Apps Create 5 apps. ```bash - az spring-cloud app create --name ${API_GATEWAY} --instance-count 1 --assign-endpoint true \ - --memory 2 \ + az spring app create --name ${API_GATEWAY} --instance-count 1 --assign-endpoint true \ + --memory 2Gi \ --jvm-options='-Xms2048m -Xmx2048m' - az spring-cloud app create --name ${ADMIN_SERVER} --instance-count 1 --assign-endpoint true \ - --memory 2 \ + az spring app create --name ${ADMIN_SERVER} --instance-count 1 --assign-endpoint true \ + --memory 2Gi \ --jvm-options='-Xms2048m -Xmx2048m' - az spring-cloud app create --name ${CUSTOMERS_SERVICE} --instance-count 1 \ - --memory 2 \ + az spring app create --name ${CUSTOMERS_SERVICE} --instance-count 1 \ + --memory 2Gi \ --jvm-options='-Xms2048m -Xmx2048m' - az spring-cloud app create --name ${VETS_SERVICE} --instance-count 1 \ - --memory 2 \ + az spring app create --name ${VETS_SERVICE} --instance-count 1 \ + --memory 2Gi \ --jvm-options='-Xms2048m -Xmx2048m' - az spring-cloud app create --name ${VISITS_SERVICE} --instance-count 1 \ - --memory 2 \ + az spring app create --name ${VISITS_SERVICE} --instance-count 1 \ + --memory 2Gi \ --jvm-options='-Xms2048m -Xmx2048m' ``` @@ -293,72 +282,91 @@ Create 5 apps. Create a MySQL database in Azure Database for MySQL. ```bash - // create mysql server - az mysql server create --resource-group ${RESOURCE_GROUP} \ - --name ${MYSQL_SERVER_NAME} --location ${REGION} \ - --admin-user ${MYSQL_SERVER_ADMIN_NAME} \ - --admin-password ${MYSQL_SERVER_ADMIN_PASSWORD} \ - --sku-name GP_Gen5_2 \ - --ssl-enforcement Disabled \ - --version 5.7 - - // allow access from Azure resources - az mysql server firewall-rule create --name allAzureIPs \ - --server ${MYSQL_SERVER_NAME} \ - --resource-group ${RESOURCE_GROUP} \ - --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0 + // create mysql server and provide access from Azure resources + az mysql flexible-server create \ + --name ${MYSQL_SERVER_NAME} \ + --resource-group ${RESOURCE_GROUP} \ + --location ${REGION} \ + --admin-user ${MYSQL_SERVER_ADMIN_NAME} \ + --admin-password ${MYSQL_SERVER_ADMIN_PASSWORD} \ + --public-access 0.0.0.0 \ + --tier Burstable \ + --sku-name Standard_B1ms \ + --storage-size 32 // allow access from your dev machine for testing - az mysql server firewall-rule create --name devMachine \ - --server ${MYSQL_SERVER_NAME} \ - --resource-group ${RESOURCE_GROUP} \ - --start-ip-address \ - --end-ip-address - - // increase connection timeout - az mysql server configuration set --name wait_timeout \ - --resource-group ${RESOURCE_GROUP} \ - --server ${MYSQL_SERVER_NAME} --value 2147483 - - // SUBSTITUTE values - mysql -u ${MYSQL_SERVER_ADMIN_LOGIN_NAME} \ - -h ${MYSQL_SERVER_FULL_NAME} -P 3306 -p - - Enter password: - Welcome to the MySQL monitor. Commands end with ; or \g. - Your MySQL connection id is 64379 - Server version: 5.6.39.0 MySQL Community Server (GPL) - - Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. - - Oracle is a registered trademark of Oracle Corporation and/or its - affiliates. Other names may be trademarks of their respective - owners. - - Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. - - mysql> CREATE DATABASE petclinic; - Query OK, 1 row affected (0.10 sec) - - mysql> CREATE USER 'root' IDENTIFIED BY 'petclinic'; - Query OK, 0 rows affected (0.11 sec) + MY_IP=$(curl http://whatismyip.akamai.com) + az mysql flexible-server firewall-rule create \ + --resource-group ${RESOURCE_GROUP} \ + --name ${MYSQL_SERVER_NAME} \ + --rule-name devMachine \ + --start-ip-address ${MY_IP} \ + --end-ip-address ${MY_IP} - mysql> GRANT ALL PRIVILEGES ON petclinic.* TO 'root'; - Query OK, 0 rows affected (1.29 sec) + // create database + az mysql flexible-server db create \ + --resource-group ${RESOURCE_GROUP} \ + --server-name ${MYSQL_SERVER_NAME} \ + --database-name ${MYSQL_DATABASE_NAME} - mysql> CALL mysql.az_load_timezone(); - Query OK, 3179 rows affected, 1 warning (6.34 sec) + // increase connection timeout + az mysql flexible-server parameter set \ + --resource-group ${RESOURCE_GROUP} \ + --server ${MYSQL_SERVER_NAME} \ + --name wait_timeout \ + --value 2147483 - mysql> SELECT name FROM mysql.time_zone_name; - ... - mysql> quit - Bye + az mysql flexible-server parameter set \ + --resource-group ${RESOURCE_GROUP} \ + --server ${MYSQL_SERVER_NAME} \ + --name time_zone \ + --value "US/Pacific" - az mysql server configuration set --name time_zone \ - --resource-group ${RESOURCE_GROUP} \ - --server ${MYSQL_SERVER_NAME} --value "US/Pacific" + # create managed identity for mysql. By assigning the identity to the mysql server, it will enable Azure AD authentication + az identity create \ + --name ${MYSQL_IDENTITY} \ + --resource-group ${RESOURCE_GROUP} \ + --location ${REGION} + + IDENTITY_ID=$(az identity show --name ${MYSQL_IDENTITY} --resource-group ${RESOURCE_GROUP} --query id -o tsv) + + // Customer service connection + az spring connection create mysql-flexible \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --app ${CUSTOMERS_SERVICE} \ + --deployment default \ + --tg ${RESOURCE_GROUP} \ + --server ${MYSQL_SERVER_NAME} \ + --database ${MYSQL_DATABASE_NAME} \ + --system-identity mysql-identity-id=$IDENTITY_ID \ + --client-type springboot + + // Vets service connection + az spring connection create mysql-flexible \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --app ${VETS_SERVICE} \ + --deployment default \ + --tg ${RESOURCE_GROUP} \ + --server ${MYSQL_SERVER_NAME} \ + --database ${MYSQL_DATABASE_NAME} \ + --system-identity mysql-identity-id=$IDENTITY_ID \ + --client-type springboot + + // Visits service connection + az spring connection create mysql-flexible \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --app ${VISITS_SERVICE} \ + --deployment default \ + --tg ${RESOURCE_GROUP} \ + --server ${MYSQL_SERVER_NAME} \ + --database ${MYSQL_DATABASE_NAME} \ + --system-identity mysql-identity-id=$IDENTITY_ID \ + --client-type springboot ``` ### Deploy Spring Boot applications and set environment variables @@ -366,45 +374,50 @@ Create a MySQL database in Azure Database for MySQL. Deploy Spring Boot applications to Azure. ```bash - az spring-cloud app deploy --name ${API_GATEWAY} \ - --jar-path ${API_GATEWAY_JAR} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql' - - - az spring-cloud app deploy --name ${ADMIN_SERVER} \ - --jar-path ${ADMIN_SERVER_JAR} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql' - - - az spring-cloud app deploy --name ${CUSTOMERS_SERVICE} \ - --jar-path ${CUSTOMERS_SERVICE_JAR} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql' \ - --env MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \ - MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \ - MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \ - MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD} - - - az spring-cloud app deploy --name ${VETS_SERVICE} \ - --jar-path ${VETS_SERVICE_JAR} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql' \ - --env MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \ - MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \ - MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \ - MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD} - - - az spring-cloud app deploy --name ${VISITS_SERVICE} \ - --jar-path ${VISITS_SERVICE_JAR} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql' \ - --env MYSQL_SERVER_FULL_NAME=${MYSQL_SERVER_FULL_NAME} \ - MYSQL_DATABASE_NAME=${MYSQL_DATABASE_NAME} \ - MYSQL_SERVER_ADMIN_LOGIN_NAME=${MYSQL_SERVER_ADMIN_LOGIN_NAME} \ - MYSQL_SERVER_ADMIN_PASSWORD=${MYSQL_SERVER_ADMIN_PASSWORD} + az spring app deploy \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --name ${API_GATEWAY} \ + --artifact-path ${API_GATEWAY_JAR} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=passwordless + +az spring app deploy \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --name ${ADMIN_SERVER} \ + --artifact-path ${ADMIN_SERVER_JAR} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=passwordless + + +az spring app deploy \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --name ${CUSTOMERS_SERVICE} \ + --artifact-path ${CUSTOMERS_SERVICE_JAR} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=passwordless + +az spring app deploy \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --name ${VETS_SERVICE} \ + --artifact-path ${VETS_SERVICE_JAR} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=passwordless + +az spring app deploy \ + --resource-group ${RESOURCE_GROUP} \ + --service ${SPRING_CLOUD_SERVICE} \ + --name ${VISITS_SERVICE} \ + --artifact-path ${VISITS_SERVICE_JAR} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=passwordless ``` ```bash - az spring-cloud app show --name ${API_GATEWAY} | grep url + az spring app show --name ${API_GATEWAY} --query properties.url --output tsv ``` Navigate to the URL provided by the previous command to open the Pet Clinic application. @@ -440,15 +453,16 @@ curl -X GET https://${SPRING_CLOUD_SERVICE}-${API_GATEWAY}.azuremicroservices.io #### Get the log stream for API Gateway and Customers Service -Use the following command to get the latest 100 lines of app console logs from Customers Service. +Use the following command to get the latest 100 lines of app console logs from Customers Service. + ```bash -az spring-cloud app logs -n ${CUSTOMERS_SERVICE} --lines 100 +az spring app logs -n ${CUSTOMERS_SERVICE} --lines 100 ``` By adding a `-f` parameter you can get real-time log streaming from the app. Try log streaming for the API Gateway app. ```bash -az spring-cloud app logs -n ${API_GATEWAY} -f +az spring app logs -n ${API_GATEWAY} -f ``` -You can use `az spring-cloud app logs -h` to explore more parameters and log stream functionalities. +You can use `az spring app logs -h` to explore more parameters and log stream functionalities. #### Open Actuator endpoints for API Gateway and Customers Service apps @@ -470,9 +484,8 @@ open https://${SPRING_CLOUD_SERVICE}-${API_GATEWAY}.azuremicroservices.io/api/cu #### Start monitoring Spring Boot apps and dependencies - in Application Insights -Open the Application Insights created by Azure Spring Cloud and start monitoring -Spring Boot applications. You can find the Application Insights in the same Resource Group where -you created an Azure Spring Cloud service instance. +Open the Application Insights created by Azure Spring Apps and start monitoring Spring Boot applications. You can find the Application Insights in the same Resource Group where +you created an Azure Spring Apps service instance. Navigate to the `Application Map` blade: ![](./media/distributed-tracking-new-ai-agent.jpg) @@ -513,7 +526,7 @@ All those three REST controllers `OwnerResource`, `PetResource` and `VisitResour You can see these custom metrics in the `Metrics` blade: ![](./media/petclinic-microservices-custom-metrics.jpg) -You can use the Availability Test feature in Application Insights and monitor +You can use the Availability Test feature in Application Insights and monitor the availability of applications: ![](./media/petclinic-microservices-availability.jpg) @@ -523,10 +536,10 @@ Navigate to the `Live Metrics` blade - you can see live metrics on screen with l #### Start monitoring Petclinic logs and metrics in Azure Log Analytics Open the Log Analytics that you created - you can find the Log Analytics in the same -Resource Group where you created an Azure Spring Cloud service instance. +Resource Group where you created an Azure Spring Apps service instance. In the Log Analyics page, selects `Logs` blade and run any of the sample queries supplied below -for Azure Spring Cloud. +for Azure Spring Apps. Type and run the following Kusto query to see application logs: ```sql @@ -554,7 +567,7 @@ Type and run the following Kusto query to see errors and exceptions thrown by e | render piechart ``` -Type and run the following Kusto query to see all in the inbound calls into Azure Spring Cloud: +Type and run the following Kusto query to see all in the inbound calls into Azure Spring Apps: ```sql AppPlatformIngressLogs | project TimeGenerated, RemoteAddr, Host, Request, Status, BodyBytesSent, RequestTime, ReqId, RequestHeaders @@ -562,7 +575,7 @@ Type and run the following Kusto query to see all in the inbound calls into Azur ``` Type and run the following Kusto query to see all the logs from the managed Spring Cloud -Config Server managed by Azure Spring Cloud: +Config Server managed by Azure Spring Apps: ```sql AppPlatformSystemLogs | where LogType contains "ConfigServer" @@ -571,7 +584,7 @@ Config Server managed by Azure Spring Cloud: ``` Type and run the following Kusto query to see all the logs from the managed Spring Cloud -Service Registry managed by Azure Spring Cloud: +Service Registry managed by Azure Spring Apps: ```sql AppPlatformSystemLogs | where LogType contains "ServiceRegistry" @@ -582,7 +595,7 @@ Service Registry managed by Azure Spring Cloud: ## Unit-2 - Automate deployments using GitHub Actions ### Prerequisites To get started with deploying this sample app from GitHub Actions, please: -1. Complete the sections above with your MySQL, Azure Spring Cloud instances and apps created. +1. Complete the sections above with your MySQL, Azure Spring Apps instances and apps created. 2. Fork this repository and turn on GitHub Actions in your fork ### Prepare secrets in your Key Vault @@ -599,7 +612,7 @@ Add the MySQL secrets to your Key Vault: az keyvault secret set --vault-name ${KEY_VAULT} --name "MYSQL-SERVER-ADMIN-PASSWORD" --value ${MYSQL_SERVER_ADMIN_PASSWORD} ``` -Create a service principle with enough scope/role to manage your Azure Spring Cloud instance: +Create a service principle with enough scope/role to manage your Azure Spring Apps instance: ```bash az ad sp create-for-rbac --role contributor --scopes /subscriptions/${SUBSCRIPTION} --sdk-auth ``` @@ -627,19 +640,19 @@ To generate a key to access the Key Vault, execute command below: ```bash az ad sp create-for-rbac --role contributor --scopes /subscriptions/${SUBSCRIPTION}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.KeyVault/vaults/${KEY_VAULT} --sdk-auth ``` -Then, follow [the steps here](https://docs.microsoft.com/azure/spring-cloud/spring-cloud-github-actions-key-vault#add-access-policies-for-the-credential) to add access policy for the Service Principal. +Then, follow [the steps here](https://learn.microsoft.com/azure/spring-apps/github-actions-key-vault#add-access-policies-for-the-credential) to add access policy for the Service Principal. -In the end, add this service principal as secret named "AZURE_CREDENTIALS" in your forked GitHub repo following [the steps here](https://docs.microsoft.com/azure/spring-cloud/how-to-github-actions?pivots=programming-language-java#set-up-github-repository-and-authenticate-1). +In the end, add this service principal as secret named "AZURE_CREDENTIALS" in your forked GitHub repo following [the steps here](https://learn.microsoft.com/azure/spring-apps/how-to-github-actions?pivots=programming-language-java#set-up-github-repository-and-authenticate-1). ### Customize your workflow -Finally, edit the workflow file `.github/workflows/action.yml` in your forked repo to fill in the subscription ID, Azure Spring Cloud instance name, and Key Vault name that you just created: +Finally, edit the workflow file `.github/workflows/action.yml` in your forked repo to fill in the subscription ID, Azure Spring Apps instance name, and Key Vault name that you just created: ```yml env: AZURE_SUBSCRIPTION: subscription-id # customize this SPRING_CLOUD_SERVICE: azure-spring-cloud-name # customize this KEYVAULT: your-keyvault-name # customize this ``` -Once you push this change, you will see GitHub Actions triggered to build and deploy all the apps in the repo to your Azure Spring Cloud instance. +Once you push this change, you will see GitHub Actions triggered to build and deploy all the apps in the repo to your Azure Spring Apps instance. ![](./media/automate-deployments-using-github-actions.png) ## Unit-3 - Manage application secrets using Azure KeyVault @@ -652,7 +665,7 @@ If you skipped the [Automation step](#automate-deployments-using-github-actions) ```bash az keyvault create --name ${KEY_VAULT} -g ${RESOURCE_GROUP} - export KEY_VAULT_URI=$(az keyvault show --name ${KEY_VAULT} | jq -r '.properties.vaultUri') + export KEY_VAULT_URI=$(az keyvault show --name ${KEY_VAULT} --query 'properties.vaultUri' --output tsv) ``` Store database connection secrets in Key Vault. @@ -671,19 +684,19 @@ Store database connection secrets in Key Vault. --name "MYSQL-SERVER-ADMIN-PASSWORD" --value ${MYSQL_SERVER_ADMIN_PASSWORD} ``` -### Enable Managed Identities for applications in Azure Spring Cloud +### Enable Managed Identities for applications in Azure Spring Apps Enable System Assigned Identities for applications and export identities to environment. ```bash - az spring-cloud app identity assign --name ${CUSTOMERS_SERVICE} - export CUSTOMERS_SERVICE_IDENTITY=$(az spring-cloud app show --name ${CUSTOMERS_SERVICE} | jq -r '.identity.principalId') + az spring app identity assign --name ${CUSTOMERS_SERVICE} + export CUSTOMERS_SERVICE_IDENTITY=$(az spring app show --name ${CUSTOMERS_SERVICE} --query 'identity.principalId' --output tsv) - az spring-cloud app identity assign --name ${VETS_SERVICE} - export VETS_SERVICE_IDENTITY=$(az spring-cloud app show --name ${VETS_SERVICE} | jq -r '.identity.principalId') + az spring app identity assign --name ${VETS_SERVICE} + export VETS_SERVICE_IDENTITY=$(az spring app show --name ${VETS_SERVICE} --query 'identity.principalId' --output tsv) - az spring-cloud app identity assign --name ${VISITS_SERVICE} - export VISITS_SERVICE_IDENTITY=$(az spring-cloud app show --name ${VISITS_SERVICE} | jq -r '.identity.principalId') + az spring app identity assign --name --name ${VISITS_SERVICE} + export VISITS_SERVICE_IDENTITY=$(az spring app show --name ${VISITS_SERVICE} --query 'identity.principalId' --output tsv) ``` ### Grant Managed Identities with access to Azure Key Vault @@ -706,32 +719,33 @@ Add an access policy to Azure Key Vault to allow Managed Identities to read secr Activate applications to load secrets from Azure Key Vault. ```bash + KEY_VAULT_URI=$(az keyvault show --name ${KEY_VAULT} --query 'properties.vaultUri' --output tsv) # DO NOT FORGET to replace the value for "azure.keyvault.uri" JVM startup parameter with your Key Vault URI - az spring-cloud app update --name ${CUSTOMERS_SERVICE} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql,key-vault -Dazure.keyvault.uri=https://petclinic-keyvault.vault.azure.net/' \ - --env + az spring app update --name ${CUSTOMERS_SERVICE} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=mysql,key-vault AZURE_KEYVAULT_URI=${KEY_VAULT_URI} # DO NOT FORGET to replace the value for "azure.keyvault.uri" JVM startup parameter with your Key Vault URI - az spring-cloud app update --name ${VETS_SERVICE} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql,key-vault -Dazure.keyvault.uri=https://petclinic-keyvault.vault.azure.net/' \ - --env + az spring app update --name ${VETS_SERVICE} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=mysql,key-vault AZURE_KEYVAULT_URI=${KEY_VAULT_URI} # DO NOT FORGET to replace the value for "azure.keyvault.uri" JVM startup parameter with your Key Vault URI - az spring-cloud app update --name ${VISITS_SERVICE} \ - --jvm-options='-Xms2048m -Xmx2048m -Dspring.profiles.active=mysql,key-vault -Dazure.keyvault.uri=https://petclinic-keyvault.vault.azure.net/' \ - --env + az spring app update --name ${VISITS_SERVICE} \ + --jvm-options='-Xms2048m -Xmx2048m' \ + --env SPRING_PROFILES_ACTIVE=mysql,key-vault AZURE_KEYVAULT_URI=${KEY_VAULT_URI} ``` ## Next Steps -In this quickstart, you've deployed an existing Spring Boot-based app using Azure CLI, Terraform and GitHub Actions. To learn more about Azure Spring Cloud, go to: +In this quickstart, you've deployed an existing Spring Boot-based app using Azure CLI, Terraform and GitHub Actions. To learn more about Azure Spring Apps, go to: -- [Azure Spring Cloud](https://azure.microsoft.com/en-us/services/spring-cloud/) -- [Azure Spring Cloud docs](https://docs.microsoft.com/en-us/azure/java/) +- [Azure Spring Apps](https://azure.microsoft.com/products/spring-apps/) +- [Azure Spring Apps docs](https://learn.microsoft.com/azure/developer/java/) - [Deploy Spring microservices from scratch](https://github.com/microsoft/azure-spring-cloud-training) - [Deploy existing Spring microservices](https://github.com/Azure-Samples/azure-spring-cloud) -- [Azure for Java Cloud Developers](https://docs.microsoft.com/en-us/azure/java/) -- [Spring Cloud Azure](https://cloud.spring.io/spring-cloud-azure/) +- [Azure for Java Cloud Developers](https://learn.microsoft.com/azure/developer/java/) +- [Spring Cloud Azure](https://spring.io/projects/spring-cloud-azure) - [Spring Cloud](https://spring.io/projects/spring-cloud) ## Credits diff --git a/docker-compose.yml b/docker-compose.yml index c064485825..600ad71456 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,6 +28,8 @@ services: entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "org.springframework.boot.loader.JarLauncher"] ports: - 8081:8081 + environment: + - SERVER_PORT=8081 visits-service: image: springcommunity/spring-petclinic-visits-service @@ -39,6 +41,8 @@ services: entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "org.springframework.boot.loader.JarLauncher"] ports: - 8082:8082 + environment: + - SERVER_PORT=8082 vets-service: image: springcommunity/spring-petclinic-vets-service @@ -50,6 +54,9 @@ services: entrypoint: ["./dockerize","-wait=tcp://discovery-server:8761","-timeout=60s","--","java", "org.springframework.boot.loader.JarLauncher"] ports: - 8083:8083 + environment: + - SERVER_PORT=8083 + api-gateway: image: springcommunity/spring-petclinic-api-gateway @@ -62,6 +69,7 @@ services: ports: - 8080:8080 + tracing-server: image: openzipkin/zipkin container_name: tracing-server diff --git a/pom.xml b/pom.xml index 2b37d1efa6..1065e4753a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ org.springframework.boot spring-boot-starter-parent - 2.5.1 + 2.7.6 org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 ${project.artifactId} pom @@ -29,15 +29,16 @@ 1.8 3.17.1 - 2.5.1 - 2020.0.3 - 2.3.10 + + 2021.0.5 + 2.6.1 springcommunity 9090 ${basedir} v0.6.1 1.2.0 + 4.5.0 @@ -60,6 +61,13 @@ ${assertj.version} test + + com.azure.spring + spring-cloud-azure-dependencies + ${version.spring.cloud.azure} + pom + import + @@ -69,7 +77,7 @@ - src/main/resources/bootstrap.yml + src/main/resources/application.yml @@ -77,13 +85,6 @@ org.springframework.boot spring-boot-maven-plugin - - true - - - true - - diff --git a/spring-petclinic-admin-server/pom.xml b/spring-petclinic-admin-server/pom.xml index 951bff91d8..07c1334cfc 100644 --- a/spring-petclinic-admin-server/pom.xml +++ b/spring-petclinic-admin-server/pom.xml @@ -12,11 +12,11 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 - 2.4.1 + 2.5.4 9090 ${basedir}/../docker diff --git a/spring-petclinic-admin-server/src/main/java/org/springframework/samples/petclinic/admin/SpringBootAdminApplication.java b/spring-petclinic-admin-server/src/main/java/org/springframework/samples/petclinic/admin/SpringBootAdminApplication.java index 7e0429f94b..49785d15e7 100644 --- a/spring-petclinic-admin-server/src/main/java/org/springframework/samples/petclinic/admin/SpringBootAdminApplication.java +++ b/spring-petclinic-admin-server/src/main/java/org/springframework/samples/petclinic/admin/SpringBootAdminApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-admin-server/src/main/resources/application.yml b/spring-petclinic-admin-server/src/main/resources/application.yml new file mode 100644 index 0000000000..d745bb18b0 --- /dev/null +++ b/spring-petclinic-admin-server/src/main/resources/application.yml @@ -0,0 +1,13 @@ +spring: + application: + name: admin-server + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} + + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 diff --git a/spring-petclinic-admin-server/src/main/resources/bootstrap.yml b/spring-petclinic-admin-server/src/main/resources/bootstrap.yml deleted file mode 100644 index d1ec2a8541..0000000000 --- a/spring-petclinic-admin-server/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: admin-server ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-api-gateway/pom.xml b/spring-petclinic-api-gateway/pom.xml index cdd39f0950..bb89ea00cd 100644 --- a/spring-petclinic-api-gateway/pom.xml +++ b/spring-petclinic-api-gateway/pom.xml @@ -11,7 +11,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java index fd13cc08d0..df86a6fc25 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/CustomersServiceClient.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/CustomersServiceClient.java index 0cb31c9b12..691254e009 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/CustomersServiceClient.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/CustomersServiceClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.samples.petclinic.api.dto.OwnerDetails; import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java index ffb3d848af..d49dbf9b3d 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java index 3d7163e9cb..4cacc61068 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/OwnerDetails.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/OwnerDetails.java index 5cea00a88f..35391c026a 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/OwnerDetails.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/OwnerDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetDetails.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetDetails.java index e9630d07da..bf064fe6fb 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetDetails.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetType.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetType.java index 63d2b20053..e6b6d9e56b 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetType.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/PetType.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/VisitDetails.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/VisitDetails.java index de3a405439..e9f3535449 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/VisitDetails.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/VisitDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/Visits.java b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/Visits.java index 90bd82bee4..fb5851f1fc 100644 --- a/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/Visits.java +++ b/spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/dto/Visits.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-api-gateway/src/main/resources/application.yml b/spring-petclinic-api-gateway/src/main/resources/application.yml index f3bc0ee829..c0192a775a 100644 --- a/spring-petclinic-api-gateway/src/main/resources/application.yml +++ b/spring-petclinic-api-gateway/src/main/resources/application.yml @@ -1,8 +1,9 @@ spring: + application: + name: api-gateway + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} cloud: - loadbalancer: - ribbon: - enabled: false gateway: routes: - id: vets-service @@ -23,3 +24,12 @@ spring: - Path=/api/customer/** filters: - StripPrefix=2 + + + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 diff --git a/spring-petclinic-api-gateway/src/main/resources/bootstrap.yml b/spring-petclinic-api-gateway/src/main/resources/bootstrap.yml deleted file mode 100644 index 9aef7487e5..0000000000 --- a/spring-petclinic-api-gateway/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: api-gateway ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-api-gateway/src/main/resources/static/index.html b/spring-petclinic-api-gateway/src/main/resources/static/index.html index 221feadb69..c947c3e3ed 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/index.html +++ b/spring-petclinic-api-gateway/src/main/resources/static/index.html @@ -46,6 +46,9 @@ + + + diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/app.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/app.js index 870aeb2097..66db62a271 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/scripts/app.js +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/app.js @@ -1,7 +1,7 @@ 'use strict'; /* App Module */ var petClinicApp = angular.module('petClinicApp', [ - 'ui.router', 'layoutNav', 'layoutFooter', 'layoutWelcome', + 'ui.router', 'infrastructure', 'layoutNav', 'layoutFooter', 'layoutWelcome', 'ownerList', 'ownerDetails', 'ownerForm', 'petForm', 'visits', 'vetList']); petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider', function( @@ -9,6 +9,7 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider' // safari turns to be lazy sending the Cache-Control header $httpProvider.defaults.headers.common["Cache-Control"] = 'no-cache'; + $httpProvider.interceptors.push('HttpErrorHandlingInterceptor'); $locationProvider.hashPrefix('!'); @@ -32,4 +33,4 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider' angular.module(mod).component(mod, { templateUrl: "scripts/fragments/" + c + ".html" }); -}); \ No newline at end of file +}); diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/httpErrorHandlingInterceptor.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/httpErrorHandlingInterceptor.js new file mode 100644 index 0000000000..f65ab687d0 --- /dev/null +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/httpErrorHandlingInterceptor.js @@ -0,0 +1,17 @@ +'use strict'; + +/** + * Global HTTP errors handler. + */ +angular.module('infrastructure') + .factory('HttpErrorHandlingInterceptor', function () { + return { + responseError: function (response) { + var error = response.data; + alert(error.error + "\r\n" + error.errors.map(function (e) { + return e.field + ": " + e.defaultMessage; + }).join("\r\n")); + return response; + } + } + }); diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/infrastructure.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/infrastructure.js new file mode 100644 index 0000000000..58dd767c42 --- /dev/null +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/infrastructure/infrastructure.js @@ -0,0 +1,3 @@ +'use strict'; + +angular.module('infrastructure', []); diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.controller.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.controller.js index f3e0e057c0..d25f7a5697 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.controller.js +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.controller.js @@ -16,20 +16,15 @@ angular.module('ownerForm') self.submitOwnerForm = function () { var id = self.owner.id; - var req; + if (id) { - req = $http.put("api/customer/owners/" + id, self.owner); + $http.put('api/customer/owners/' + id, self.owner).then(function () { + $state.go('ownerDetails', {ownerId: ownerId}); + }); } else { - req = $http.post("api/customer/owners", self.owner); + $http.post('api/customer/owners', self.owner).then(function () { + $state.go('owners'); + }); } - - req.then(function () { - $state.go('owners'); - }, function (response) { - var error = response.data; - alert(error.error + "\r\n" + error.errors.map(function (e) { - return e.field + ": " + e.defaultMessage; - }).join("\r\n")); - }); }; }]); diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.template.html b/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.template.html index 0d49cfb92d..17e97a3f2f 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.template.html +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/owner-form/owner-form.template.html @@ -27,7 +27,8 @@

Owner

- + Telephone is required.
diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js index 9bf24f190e..93bbb6c8b3 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/pet-form/pet-form.controller.js @@ -46,13 +46,7 @@ angular.module('petForm') } req.then(function () { - $state.go("owners", {ownerId: ownerId}); - }, function (response) { - var error = response.data; - error.errors = error.errors || []; - alert(error.error + "\r\n" + error.errors.map(function (e) { - return e.field + ": " + e.defaultMessage; - }).join("\r\n")); + $state.go('ownerDetails', {ownerId: ownerId}); }); }; }]); diff --git a/spring-petclinic-api-gateway/src/main/resources/static/scripts/visits/visits.controller.js b/spring-petclinic-api-gateway/src/main/resources/static/scripts/visits/visits.controller.js index 992765831c..d68798b39d 100644 --- a/spring-petclinic-api-gateway/src/main/resources/static/scripts/visits/visits.controller.js +++ b/spring-petclinic-api-gateway/src/main/resources/static/scripts/visits/visits.controller.js @@ -19,12 +19,7 @@ angular.module('visits') }; $http.post(url, data).then(function () { - $state.go("owners", { ownerId: $stateParams.ownerId }); - }, function (response) { - var error = response.data; - alert(error.error + "\r\n" + error.errors.map(function (e) { - return e.field + ": " + e.defaultMessage; - }).join("\r\n")); + $state.go('ownerDetails', { ownerId: $stateParams.ownerId }); }); }; }]); diff --git a/spring-petclinic-api-gateway/src/test/resources/bootstrap-test.yml b/spring-petclinic-api-gateway/src/test/resources/application-test.yml similarity index 100% rename from spring-petclinic-api-gateway/src/test/resources/bootstrap-test.yml rename to spring-petclinic-api-gateway/src/test/resources/application-test.yml diff --git a/spring-petclinic-config-server/pom.xml b/spring-petclinic-config-server/pom.xml index ef45071e88..cca4c4983e 100644 --- a/spring-petclinic-config-server/pom.xml +++ b/spring-petclinic-config-server/pom.xml @@ -11,7 +11,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 diff --git a/spring-petclinic-config-server/src/main/java/org/springframework/samples/petclinic/config/ConfigServerApplication.java b/spring-petclinic-config-server/src/main/java/org/springframework/samples/petclinic/config/ConfigServerApplication.java index 7d91d10127..e6b810b589 100644 --- a/spring-petclinic-config-server/src/main/java/org/springframework/samples/petclinic/config/ConfigServerApplication.java +++ b/spring-petclinic-config-server/src/main/java/org/springframework/samples/petclinic/config/ConfigServerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-config-server/src/main/resources/bootstrap.yml b/spring-petclinic-config-server/src/main/resources/application.yml similarity index 91% rename from spring-petclinic-config-server/src/main/resources/bootstrap.yml rename to spring-petclinic-config-server/src/main/resources/application.yml index 43e3e9906b..9a58811ba7 100644 --- a/spring-petclinic-config-server/src/main/resources/bootstrap.yml +++ b/spring-petclinic-config-server/src/main/resources/application.yml @@ -5,6 +5,7 @@ spring: server: git: uri: https://github.com/spring-petclinic/spring-petclinic-microservices-config + default-label: main # Use the File System Backend to avoid git pulling. Enable "native" profile in the Config Server. native: searchLocations: file:///${GIT_REPO} diff --git a/spring-petclinic-config-server/src/test/java/org/springframework/samples/petclinic/config/PetclinicConfigServerApplicationTests.java b/spring-petclinic-config-server/src/test/java/org/springframework/samples/petclinic/config/PetclinicConfigServerApplicationTests.java index e4cd33f3a1..e3d5191a4f 100644 --- a/spring-petclinic-config-server/src/test/java/org/springframework/samples/petclinic/config/PetclinicConfigServerApplicationTests.java +++ b/spring-petclinic-config-server/src/test/java/org/springframework/samples/petclinic/config/PetclinicConfigServerApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/pom.xml b/spring-petclinic-customers-service/pom.xml index 448f5b35ef..55109e26dd 100644 --- a/spring-petclinic-customers-service/pom.xml +++ b/spring-petclinic-customers-service/pom.xml @@ -11,7 +11,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 @@ -62,7 +62,13 @@ spring-cloud-sleuth-zipkin --> - + + + + com.azure.spring + spring-cloud-azure-starter-jdbc-mysql + + mysql diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java index 3c757c9d47..867cdc198a 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java index 360e7652f3..88860faa47 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Owner.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,10 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.Setter; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; @@ -45,6 +47,7 @@ * @author Sam Brannen * @author Michael Isvy * @author Maciej Szarlinski + * @author Ramazan Sakin */ @Entity @Table(name = "owners") @@ -52,76 +55,43 @@ public class Owner { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Getter private Integer id; + @Getter + @Setter @Column(name = "first_name") - @NotEmpty + @NotBlank private String firstName; + @Getter + @Setter @Column(name = "last_name") - @NotEmpty + @NotBlank private String lastName; + @Getter + @Setter @Column(name = "address") - @NotEmpty + @NotBlank private String address; + @Getter + @Setter @Column(name = "city") - @NotEmpty + @NotBlank private String city; + @Getter + @Setter @Column(name = "telephone") - @NotEmpty - @Digits(fraction = 0, integer = 10) + @NotBlank + @Digits(fraction = 0, integer = 12) private String telephone; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "owner") private Set pets; - public Integer getId() { - return id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(final String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(final String lastName) { - this.lastName = lastName; - } - - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - protected Set getPetsInternal() { if (this.pets == null) { this.pets = new HashSet<>(); diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/OwnerRepository.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/OwnerRepository.java index a9eec088a2..aa720f24f1 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/OwnerRepository.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/OwnerRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Pet.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Pet.java index e0d28a9fd9..b89924f0dd 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Pet.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/Pet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import javax.persistence.TemporalType; import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; import org.springframework.core.style.ToStringCreator; /** @@ -38,7 +39,9 @@ * @author Juergen Hoeller * @author Sam Brannen * @author Maciej Szarlinski + * @author Ramazan Sakin */ +@Data @Entity @Table(name = "pets") public class Pet { @@ -62,46 +65,6 @@ public class Pet { @JsonIgnore private Owner owner; - public Integer getId() { - return id; - } - - public void setId(final Integer id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public void setName(final String name) { - this.name = name; - } - - public Date getBirthDate() { - return birthDate; - } - - public void setBirthDate(final Date birthDate) { - this.birthDate = birthDate; - } - - public PetType getType() { - return type; - } - - public void setType(final PetType type) { - this.type = type; - } - - public Owner getOwner() { - return owner; - } - - public void setOwner(final Owner owner) { - this.owner = owner; - } - @Override public String toString() { return new ToStringCreator(this) diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetRepository.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetRepository.java index 93feb49abf..5bd16dbee5 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetRepository.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetType.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetType.java index 5ca44874b2..3a7162fda8 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetType.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/model/PetType.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ */ package org.springframework.samples.petclinic.customers.model; +import lombok.Getter; +import lombok.Setter; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -24,27 +27,21 @@ /** * @author Juergen Hoeller + * @author Ramazan Sakin * Can be Cat, Dog, Hamster... */ @Entity @Table(name = "types") public class PetType { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Getter + @Setter private Integer id; + @Getter + @Setter @Column(name = "name") private String name; - - public Integer getId() { - return id; - } - - public void setId(final Integer id) { - this.id = id; - } - - public String getName() { - return this.name; - } } diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java index c9ea4b929f..b867f1aa21 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import javax.validation.constraints.Min; import java.util.List; import java.util.Optional; @@ -56,7 +57,7 @@ public Owner createOwner(@Valid @RequestBody Owner owner) { * Read single Owner */ @GetMapping(value = "/{ownerId}") - public Optional findOwner(@PathVariable("ownerId") int ownerId) { + public Optional findOwner(@PathVariable("ownerId") @Min(1) int ownerId) { return ownerRepository.findById(ownerId); } @@ -73,10 +74,10 @@ public List findAll() { */ @PutMapping(value = "/{ownerId}") @ResponseStatus(HttpStatus.NO_CONTENT) - public void updateOwner(@PathVariable("ownerId") int ownerId, @Valid @RequestBody Owner ownerRequest) { + public void updateOwner(@PathVariable("ownerId") @Min(1) int ownerId, @Valid @RequestBody Owner ownerRequest) { final Optional owner = ownerRepository.findById(ownerId); - final Owner ownerModel = owner.orElseThrow(() -> new ResourceNotFoundException("Owner "+ownerId+" not found")); + // This is done by hand for simplicity purpose. In a real life use-case we should consider using MapStruct. ownerModel.setFirstName(ownerRequest.getFirstName()); ownerModel.setLastName(ownerRequest.getLastName()); diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetDetails.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetDetails.java index 2cda1e7878..6e61fc0bed 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetDetails.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetRequest.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetRequest.java index f7b68f6504..b2e2653169 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetRequest.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java index 3b8bdd8870..7ec597a4b4 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.springframework.samples.petclinic.customers.model.*; import org.springframework.web.bind.annotation.*; +import javax.validation.constraints.Min; import java.util.List; import java.util.Optional; @@ -30,6 +31,7 @@ * @author Ken Krebs * @author Arjen Poutsma * @author Maciej Szarlinski + * @author Ramazan Sakin */ @RestController @Timed("petclinic.pet") @@ -50,13 +52,13 @@ public List getPetTypes() { @ResponseStatus(HttpStatus.CREATED) public Pet processCreationForm( @RequestBody PetRequest petRequest, - @PathVariable("ownerId") int ownerId) { + @PathVariable("ownerId") @Min(1) int ownerId) { - final Pet pet = new Pet(); final Optional optionalOwner = ownerRepository.findById(ownerId); Owner owner = optionalOwner.orElseThrow(() -> new ResourceNotFoundException("Owner "+ownerId+" not found")); - owner.addPet(pet); + final Pet pet = new Pet(); + owner.addPet(pet); return save(pet, petRequest); } diff --git a/spring-petclinic-customers-service/src/main/resources/application.properties b/spring-petclinic-customers-service/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-petclinic-customers-service/src/main/resources/application.yml b/spring-petclinic-customers-service/src/main/resources/application.yml new file mode 100644 index 0000000000..7c95adf788 --- /dev/null +++ b/spring-petclinic-customers-service/src/main/resources/application.yml @@ -0,0 +1,13 @@ +spring: + application: + name: customers-service + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} + + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 diff --git a/spring-petclinic-customers-service/src/main/resources/bootstrap.yml b/spring-petclinic-customers-service/src/main/resources/bootstrap.yml deleted file mode 100644 index 58281a4441..0000000000 --- a/spring-petclinic-customers-service/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: customers-service ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-customers-service/src/main/resources/db/hsqldb/data.sql b/spring-petclinic-customers-service/src/main/resources/data-hsqldb.sql similarity index 100% rename from spring-petclinic-customers-service/src/main/resources/db/hsqldb/data.sql rename to spring-petclinic-customers-service/src/main/resources/data-hsqldb.sql diff --git a/spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql b/spring-petclinic-customers-service/src/main/resources/data-mysql.sql similarity index 100% rename from spring-petclinic-customers-service/src/main/resources/db/mysql/data.sql rename to spring-petclinic-customers-service/src/main/resources/data-mysql.sql diff --git a/spring-petclinic-customers-service/src/main/resources/db/hsqldb/schema.sql b/spring-petclinic-customers-service/src/main/resources/schema-hsqldb.sql similarity index 97% rename from spring-petclinic-customers-service/src/main/resources/db/hsqldb/schema.sql rename to spring-petclinic-customers-service/src/main/resources/schema-hsqldb.sql index 9aa6666bf9..33d42ee5ac 100644 --- a/spring-petclinic-customers-service/src/main/resources/db/hsqldb/schema.sql +++ b/spring-petclinic-customers-service/src/main/resources/schema-hsqldb.sql @@ -14,7 +14,7 @@ CREATE TABLE owners ( last_name VARCHAR(30), address VARCHAR(255), city VARCHAR(80), - telephone VARCHAR(20) + telephone VARCHAR(12) ); CREATE INDEX owners_last_name ON owners (last_name); diff --git a/spring-petclinic-customers-service/src/main/resources/db/mysql/schema.sql b/spring-petclinic-customers-service/src/main/resources/schema-mysql.sql similarity index 84% rename from spring-petclinic-customers-service/src/main/resources/db/mysql/schema.sql rename to spring-petclinic-customers-service/src/main/resources/schema-mysql.sql index 720913829a..67eb65fe48 100644 --- a/spring-petclinic-customers-service/src/main/resources/db/mysql/schema.sql +++ b/spring-petclinic-customers-service/src/main/resources/schema-mysql.sql @@ -1,7 +1,7 @@ -CREATE DATABASE IF NOT EXISTS petclinic; -GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; +-- CREATE DATABASE IF NOT EXISTS petclinic; +-- GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; -USE petclinic; +-- USE petclinic; CREATE TABLE IF NOT EXISTS types ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/spring-petclinic-customers-service/src/test/resources/application-test.yml b/spring-petclinic-customers-service/src/test/resources/application-test.yml index 0abdac4430..b9c699b5f0 100644 --- a/spring-petclinic-customers-service/src/test/resources/application-test.yml +++ b/spring-petclinic-customers-service/src/test/resources/application-test.yml @@ -1,9 +1,18 @@ -spring.jpa.hibernate.ddl-auto: none - spring: - datasource: - schema: classpath*:db/hsqldb/schema.sql - data: classpath*:db/hsqldb/data.sql + cloud: + config: + enabled: false + sql: + init: + schema-locations: classpath*:db/hsqldb/schema.sql + data-locations: classpath*:db/hsqldb/data.sql + jpa: + hibernate: + ddl-auto: none + +eureka: + client: + enabled: false logging.level.org.springframework: INFO diff --git a/spring-petclinic-customers-service/src/test/resources/bootstrap-test.yml b/spring-petclinic-customers-service/src/test/resources/bootstrap-test.yml deleted file mode 100644 index cb8e4f5f71..0000000000 --- a/spring-petclinic-customers-service/src/test/resources/bootstrap-test.yml +++ /dev/null @@ -1,2 +0,0 @@ -spring.cloud.config.enabled: false -eureka.client.enabled: false diff --git a/spring-petclinic-discovery-server/pom.xml b/spring-petclinic-discovery-server/pom.xml index f08859f303..24766267c2 100644 --- a/spring-petclinic-discovery-server/pom.xml +++ b/spring-petclinic-discovery-server/pom.xml @@ -11,7 +11,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 @@ -40,6 +40,10 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-server + + org.springframework.cloud + spring-cloud-starter-config + diff --git a/spring-petclinic-discovery-server/src/main/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplication.java b/spring-petclinic-discovery-server/src/main/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplication.java index 6c2d281ec7..56c49ed2d5 100644 --- a/spring-petclinic-discovery-server/src/main/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplication.java +++ b/spring-petclinic-discovery-server/src/main/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-discovery-server/src/main/resources/application.yml b/spring-petclinic-discovery-server/src/main/resources/application.yml new file mode 100644 index 0000000000..9fbcbc588a --- /dev/null +++ b/spring-petclinic-discovery-server/src/main/resources/application.yml @@ -0,0 +1,21 @@ +spring: + application: + name: discovery-server + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} + +# Avoid some debugging logs at startup +logging: + level: + org: + springframework: + boot: INFO + web: INFO + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 + diff --git a/spring-petclinic-discovery-server/src/main/resources/bootstrap.yml b/spring-petclinic-discovery-server/src/main/resources/bootstrap.yml deleted file mode 100644 index eba87c89e9..0000000000 --- a/spring-petclinic-discovery-server/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: discovery-server ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-discovery-server/src/test/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplicationTests.java b/spring-petclinic-discovery-server/src/test/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplicationTests.java index a1ede35e1f..8bcc0afd57 100644 --- a/spring-petclinic-discovery-server/src/test/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplicationTests.java +++ b/spring-petclinic-discovery-server/src/test/java/org/springframework/samples/petclinic/discovery/DiscoveryServerApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/pom.xml b/spring-petclinic-vets-service/pom.xml index 060d6197c7..484d1984f0 100644 --- a/spring-petclinic-vets-service/pom.xml +++ b/spring-petclinic-vets-service/pom.xml @@ -11,7 +11,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 @@ -74,6 +74,12 @@ --> + + + com.azure.spring + spring-cloud-azure-starter-jdbc-mysql + + org.projectlombok diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java index 2f5cb36636..e11e1b00d8 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Specialty.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Specialty.java index 4a22dd167d..c5c0869c6e 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Specialty.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Specialty.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ */ package org.springframework.samples.petclinic.vets.model; +import lombok.Getter; +import lombok.Setter; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -26,30 +29,20 @@ * Models a {@link Vet Vet's} specialty (for example, dentistry). * * @author Juergen Hoeller + * @author Ramazan Sakin */ + @Entity @Table(name = "specialties") public class Specialty { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Getter private Integer id; + @Getter + @Setter @Column(name = "name") private String name; - public Integer getId() { - return id; - } - - public void setId(final Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } } diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Vet.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Vet.java index cddb6a9e3b..4976a39bce 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Vet.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/Vet.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,11 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import javax.xml.bind.annotation.XmlElement; +import lombok.Getter; +import lombok.Setter; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; @@ -45,6 +47,7 @@ * @author Sam Brannen * @author Arjen Poutsma * @author Maciej Szarlinski + * @author Ramazan Sakin */ @Entity @Table(name = "vets") @@ -52,14 +55,20 @@ public class Vet { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Getter + @Setter private Integer id; @Column(name = "first_name") - @NotEmpty + @NotBlank + @Getter + @Setter private String firstName; @Column(name = "last_name") - @NotEmpty + @NotBlank + @Getter + @Setter private String lastName; @ManyToMany(fetch = FetchType.EAGER) @@ -67,30 +76,6 @@ public class Vet { inverseJoinColumns = @JoinColumn(name = "specialty_id")) private Set specialties; - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - protected Set getSpecialtiesInternal() { if (this.specialties == null) { this.specialties = new HashSet<>(); diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/VetRepository.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/VetRepository.java index 67e2571333..cb22d143b0 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/VetRepository.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/model/VetRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/CacheConfig.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/CacheConfig.java index 6941a14466..2f3fb794a1 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/CacheConfig.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/CacheConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/VetsProperties.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/VetsProperties.java index e6529f1020..017bffe717 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/VetsProperties.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/system/VetsProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/VetResource.java b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/VetResource.java index d61d5dda17..7e0a57481c 100644 --- a/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/VetResource.java +++ b/spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/VetResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/main/resources/application.properties b/spring-petclinic-vets-service/src/main/resources/application.properties deleted file mode 100644 index 68f17e806f..0000000000 --- a/spring-petclinic-vets-service/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.profiles.active=production -spring.cache.cache-names=vets diff --git a/spring-petclinic-vets-service/src/main/resources/application.yml b/spring-petclinic-vets-service/src/main/resources/application.yml new file mode 100644 index 0000000000..983a015db8 --- /dev/null +++ b/spring-petclinic-vets-service/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + application: + name: vets-service + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} + cache: + cache-names: vets + profiles: + active: production + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 diff --git a/spring-petclinic-vets-service/src/main/resources/bootstrap.yml b/spring-petclinic-vets-service/src/main/resources/bootstrap.yml deleted file mode 100644 index bc2f683e5e..0000000000 --- a/spring-petclinic-vets-service/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: vets-service ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-vets-service/src/main/resources/db/hsqldb/data.sql b/spring-petclinic-vets-service/src/main/resources/data-hsqldb.sql similarity index 100% rename from spring-petclinic-vets-service/src/main/resources/db/hsqldb/data.sql rename to spring-petclinic-vets-service/src/main/resources/data-hsqldb.sql diff --git a/spring-petclinic-vets-service/src/main/resources/db/mysql/data.sql b/spring-petclinic-vets-service/src/main/resources/data-mysql.sql similarity index 100% rename from spring-petclinic-vets-service/src/main/resources/db/mysql/data.sql rename to spring-petclinic-vets-service/src/main/resources/data-mysql.sql diff --git a/spring-petclinic-vets-service/src/main/resources/db/hsqldb/schema.sql b/spring-petclinic-vets-service/src/main/resources/schema-hsqldb.sql similarity index 100% rename from spring-petclinic-vets-service/src/main/resources/db/hsqldb/schema.sql rename to spring-petclinic-vets-service/src/main/resources/schema-hsqldb.sql diff --git a/spring-petclinic-vets-service/src/main/resources/db/mysql/schema.sql b/spring-petclinic-vets-service/src/main/resources/schema-mysql.sql similarity index 81% rename from spring-petclinic-vets-service/src/main/resources/db/mysql/schema.sql rename to spring-petclinic-vets-service/src/main/resources/schema-mysql.sql index 4f9af3d1bd..a4c847e533 100644 --- a/spring-petclinic-vets-service/src/main/resources/db/mysql/schema.sql +++ b/spring-petclinic-vets-service/src/main/resources/schema-mysql.sql @@ -1,7 +1,7 @@ -CREATE DATABASE IF NOT EXISTS petclinic; -GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; +-- CREATE DATABASE IF NOT EXISTS petclinic; +-- GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; -USE petclinic; +-- USE petclinic; CREATE TABLE IF NOT EXISTS vets ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/spring-petclinic-vets-service/src/test/java/org/springframework/samples/petclinic/vets/web/VetResourceTest.java b/spring-petclinic-vets-service/src/test/java/org/springframework/samples/petclinic/vets/web/VetResourceTest.java index 83e6a6fb61..05e29b9229 100644 --- a/spring-petclinic-vets-service/src/test/java/org/springframework/samples/petclinic/vets/web/VetResourceTest.java +++ b/spring-petclinic-vets-service/src/test/java/org/springframework/samples/petclinic/vets/web/VetResourceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-vets-service/src/test/resources/application-test.yml b/spring-petclinic-vets-service/src/test/resources/application-test.yml index 2d18cfdeaf..684fa89889 100644 --- a/spring-petclinic-vets-service/src/test/resources/application-test.yml +++ b/spring-petclinic-vets-service/src/test/resources/application-test.yml @@ -1,9 +1,18 @@ -spring.jpa.hibernate.ddl-auto: none - spring: - datasource: - schema: classpath*:db/hsqldb/schema.sql - data: classpath*:db/hsqldb/data.sql + cloud: + config: + enabled: false + sql: + init: + schema-locations: classpath*:db/hsqldb/schema.sql + data-locations: classpath*:db/hsqldb/data.sql + jpa: + hibernate: + ddl-auto: none + +eureka: + client: + enabled: false vets: cache: diff --git a/spring-petclinic-vets-service/src/test/resources/bootstrap-test.yml b/spring-petclinic-vets-service/src/test/resources/bootstrap-test.yml deleted file mode 100644 index cb8e4f5f71..0000000000 --- a/spring-petclinic-vets-service/src/test/resources/bootstrap-test.yml +++ /dev/null @@ -1,2 +0,0 @@ -spring.cloud.config.enabled: false -eureka.client.enabled: false diff --git a/spring-petclinic-visits-service/pom.xml b/spring-petclinic-visits-service/pom.xml index 8be68417ad..53e23d507b 100644 --- a/spring-petclinic-visits-service/pom.xml +++ b/spring-petclinic-visits-service/pom.xml @@ -12,7 +12,7 @@ org.springframework.samples spring-petclinic-microservices - 2.5.1 + 2.7.6 @@ -64,6 +64,12 @@ --> + + + com.azure.spring + spring-cloud-azure-starter-jdbc-mysql + + org.projectlombok diff --git a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/VisitsServiceApplication.java b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/VisitsServiceApplication.java index 51a0ecd8c6..78f2963f8d 100644 --- a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/VisitsServiceApplication.java +++ b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/VisitsServiceApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/Visit.java b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/Visit.java index f799b43a03..deede8eed1 100644 --- a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/Visit.java +++ b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/Visit.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,11 @@ package org.springframework.samples.petclinic.visits.model; import com.fasterxml.jackson.annotation.JsonFormat; -import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -26,19 +30,19 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.NoArgsConstructor; +import java.util.Date; /** * Simple JavaBean domain object representing a visit. * * @author Ken Krebs * @author Maciej Szarlinski + * @author Ramazan Sakin */ @Entity @Table(name = "visits") @Builder(builderMethodName = "visit") +@Data @NoArgsConstructor @AllArgsConstructor public class Visit { @@ -60,24 +64,4 @@ public class Visit { @Column(name = "pet_id") private int petId; - public Integer getId() { - return id; - } - - public Date getDate() { - return date; - } - - public String getDescription() { - return description; - } - - public int getPetId() { - return petId; - } - - public void setPetId(final int petId) { - this.petId = petId; - } - } diff --git a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/VisitRepository.java b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/VisitRepository.java index 063b3d2709..bd7a6d726b 100644 --- a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/VisitRepository.java +++ b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/model/VisitRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/web/VisitResource.java b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/web/VisitResource.java index 4c921d811e..ab940b5bc3 100644 --- a/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/web/VisitResource.java +++ b/spring-petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/web/VisitResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ import java.util.List; import javax.validation.Valid; +import javax.validation.constraints.Min; import io.micrometer.core.annotation.Timed; import lombok.RequiredArgsConstructor; @@ -39,6 +40,7 @@ * @author Arjen Poutsma * @author Michael Isvy * @author Maciej Szarlinski + * @author Ramazan Sakin */ @RestController @RequiredArgsConstructor @@ -50,9 +52,9 @@ class VisitResource { @PostMapping("owners/*/pets/{petId}/visits") @ResponseStatus(HttpStatus.CREATED) - public Visit create( + public Visit create( @Valid @RequestBody Visit visit, - @PathVariable("petId") int petId) { + @PathVariable("petId") @Min(1) int petId) { visit.setPetId(petId); log.info("Saving visit {}", visit); @@ -60,12 +62,12 @@ public Visit create( } @GetMapping("owners/*/pets/{petId}/visits") - public List visits(@PathVariable("petId") int petId) { + public List visits(@PathVariable("petId") @Min(1) int petId) { return visitRepository.findByPetId(petId); } @GetMapping("pets/visits") - public Visits visitsMultiGet(@RequestParam("petId") List petIds) { + public Visits visitsMultiGet(@RequestParam("petId") List petIds) { final List byPetIdIn = visitRepository.findByPetIdIn(petIds); return new Visits(byPetIdIn); } diff --git a/spring-petclinic-visits-service/src/main/resources/application.properties b/spring-petclinic-visits-service/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-petclinic-visits-service/src/main/resources/application.yml b/spring-petclinic-visits-service/src/main/resources/application.yml new file mode 100644 index 0000000000..ada02194cf --- /dev/null +++ b/spring-petclinic-visits-service/src/main/resources/application.yml @@ -0,0 +1,13 @@ +spring: + application: + name: visits-service + config: + import: optional:configserver:${CONFIG_SERVER_URL:http://localhost:8888/} + + +--- +spring: + config: + activate: + on-profile: docker + import: configserver:http://config-server:8888 diff --git a/spring-petclinic-visits-service/src/main/resources/bootstrap.yml b/spring-petclinic-visits-service/src/main/resources/bootstrap.yml deleted file mode 100644 index 92f4fcae36..0000000000 --- a/spring-petclinic-visits-service/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,14 +0,0 @@ -spring: - cloud: - config: - uri: http://localhost:8888 - application: - name: visits-service ---- -spring: - config: - activate: - on-profile: docker - cloud: - config: - uri: http://config-server:8888 diff --git a/spring-petclinic-visits-service/src/main/resources/db/hsqldb/data.sql b/spring-petclinic-visits-service/src/main/resources/data-hsqldb.sql similarity index 100% rename from spring-petclinic-visits-service/src/main/resources/db/hsqldb/data.sql rename to spring-petclinic-visits-service/src/main/resources/data-hsqldb.sql diff --git a/spring-petclinic-visits-service/src/main/resources/db/mysql/data.sql b/spring-petclinic-visits-service/src/main/resources/data-mysql.sql similarity index 100% rename from spring-petclinic-visits-service/src/main/resources/db/mysql/data.sql rename to spring-petclinic-visits-service/src/main/resources/data-mysql.sql diff --git a/spring-petclinic-visits-service/src/main/resources/db/hsqldb/schema.sql b/spring-petclinic-visits-service/src/main/resources/schema-hsqldb.sql similarity index 100% rename from spring-petclinic-visits-service/src/main/resources/db/hsqldb/schema.sql rename to spring-petclinic-visits-service/src/main/resources/schema-hsqldb.sql diff --git a/spring-petclinic-visits-service/src/main/resources/db/mysql/schema.sql b/spring-petclinic-visits-service/src/main/resources/schema-mysql.sql similarity index 63% rename from spring-petclinic-visits-service/src/main/resources/db/mysql/schema.sql rename to spring-petclinic-visits-service/src/main/resources/schema-mysql.sql index 65c448c69c..c9e76dcb0c 100644 --- a/spring-petclinic-visits-service/src/main/resources/db/mysql/schema.sql +++ b/spring-petclinic-visits-service/src/main/resources/schema-mysql.sql @@ -1,7 +1,7 @@ -CREATE DATABASE IF NOT EXISTS petclinic; -GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; +-- CREATE DATABASE IF NOT EXISTS petclinic; +-- GRANT ALL PRIVILEGES ON petclinic.* TO pc@localhost IDENTIFIED BY 'pc'; -USE petclinic; +-- USE petclinic; CREATE TABLE IF NOT EXISTS visits ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, diff --git a/spring-petclinic-visits-service/src/test/resources/application-test.yml b/spring-petclinic-visits-service/src/test/resources/application-test.yml index 0abdac4430..b9c699b5f0 100644 --- a/spring-petclinic-visits-service/src/test/resources/application-test.yml +++ b/spring-petclinic-visits-service/src/test/resources/application-test.yml @@ -1,9 +1,18 @@ -spring.jpa.hibernate.ddl-auto: none - spring: - datasource: - schema: classpath*:db/hsqldb/schema.sql - data: classpath*:db/hsqldb/data.sql + cloud: + config: + enabled: false + sql: + init: + schema-locations: classpath*:db/hsqldb/schema.sql + data-locations: classpath*:db/hsqldb/data.sql + jpa: + hibernate: + ddl-auto: none + +eureka: + client: + enabled: false logging.level.org.springframework: INFO diff --git a/spring-petclinic-visits-service/src/test/resources/bootstrap-test.yml b/spring-petclinic-visits-service/src/test/resources/bootstrap-test.yml deleted file mode 100644 index cb8e4f5f71..0000000000 --- a/spring-petclinic-visits-service/src/test/resources/bootstrap-test.yml +++ /dev/null @@ -1,2 +0,0 @@ -spring.cloud.config.enabled: false -eureka.client.enabled: false