title | description | author | ms.author | ms.service | ms.topic | ms.date | ms.custom | ms.devlang |
---|---|---|---|---|---|---|---|---|
Tutorial: Deploy a Spring Cloud Application Connected to Azure Database for MySQL with Service Connector |
Create a Spring Boot application connected to Azure Database for MySQL with Service Connector. |
shizn |
xshi |
service-connector |
tutorial |
05/03/2022 |
devx-track-azurecli, event-tier1-build-2022 |
azurecli |
Tutorial: Deploy Spring Cloud Application Connected to Azure Database for MySQL with Service Connector
In this tutorial, you will complete the following tasks using the Azure portal or the Azure CLI. Both methods are explained in the following procedures.
[!div class="checklist"]
- Provision an instance of Azure Spring Cloud
- Build and deploy apps to Azure Spring Cloud
- Integrate Azure Spring Cloud with Azure Database for MySQL with Service Connector
- Install JDK 8 or JDK 11
- Sign up for an Azure subscription
- Install the Azure CLI version 2.0.67 or higher and install the Azure Spring Cloud extension with the command:
az extension add --name spring-cloud
The following procedure uses the Azure CLI extension to provision an instance of Azure Spring Cloud.
-
Update Azure CLI with the Azure Spring Cloud extension.
az extension update --name spring-cloud
-
Sign in to the Azure CLI and choose your active subscription.
az login az account list -o table az account set --subscription <Name or ID of subscription, skip if you only have 1 subscription>
-
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 a resource group to contain your Azure Spring Cloud service and an instance of the Azure Spring Cloud service.
az group create --name ServiceConnector-tutorial-rg az spring-cloud create -n <service instance name> -g ServiceConnector-tutorial-rg
The following procedure uses the Azure CLI extension to provision an instance of Azure Database for MySQL.
-
Install the db-up extension.
az extension add --name db-up
-
Create an Azure Database for MySQL server using the following command:
az mysql up --resource-group ServiceConnector-tutorial-rg --admin-user <admin-username> --admin-password <admin-password>
For
<admin-username>
and<admin-password>
, specify credentials to create an administrator user for this MySQL server. The admin username can't be azure_superuser, azure_pg_admin, admin, administrator, root, guest, or public. It can't start with pg_. The password must contain 8 to 128 characters from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (for example, !, #, %). The password cannot contain username.The server is created with the following default values (unless you manually override them):
Setting Default value Description server-name System generated A unique name that identifies your Azure Database for MySQL server. sku-name GP_Gen5_2 The name of the sku. Follows the convention {pricing tier}_{compute generation}_{vCores} in shorthand. The default is a General Purpose Gen5 server with 2 vCores. See our pricing page for more information about the tiers. backup-retention 7 How long a backup should be retained. Unit is days. geo-redundant-backup Disabled Whether geo-redundant backups should be enabled for this server or not. location westus2 The Azure location for the server. ssl-enforcement Enabled Whether SSL should be enabled or not for this server. storage-size 5120 The storage capacity of the server (unit is megabytes). version 5.7 The MySQL major version.
Note
For more information about the az mysql up
command and its additional parameters, see the Azure CLI documentation.
Once your server is created, it comes with the following settings:
- A firewall rule called "devbox" is created. The Azure CLI attempts to detect the IP address of the machine the
az mysql up
command is run from and allows that IP address. - "Allow access to Azure services" is set to ON. This setting configures the server's firewall to accept connections from all Azure resources, including resources not in your subscription.
- The
wait_timeout
parameter is set to 8 hours - An empty database named
sampledb
is created - A new user named "root" with privileges to
sampledb
is created
-
Create the app with public endpoint assigned. If you selected Java version 11 when generating the Spring Cloud project, include the
--runtime-version=Java_11
switch.az spring-cloud app create -n hellospring -s <service instance name> -g ServiceConnector-tutorial-rg --assign-endpoint true
-
Create service connections between Spring Cloud to MySQL database.
az spring-cloud connection create mysql
[!NOTE] If you see the error message "The subscription is not registered to use Microsoft.ServiceLinker", please run
az provider register -n Microsoft.ServiceLinker
to register the Service Connector resource provider and run the connection command again. -
Clone sample code
git clone https://github.com/Azure-Samples/serviceconnector-springcloud-mysql-springboot.git
-
Build the project using Maven.
cd serviceconnector-springcloud-mysql-springboot mvn clean package -DskipTests
-
Deploy the JAR file for the app (
target/demo-0.0.1-SNAPSHOT.jar
).az spring-cloud app deploy -n hellospring -s <service instance name> -g ServiceConnector-tutorial-rg --artifact-path target/demo-0.0.1-SNAPSHOT.jar
-
Query app status after deployment with the following command.
az spring-cloud app list -o table
You should see output like the following.
Name Location ResourceGroup Production Deployment Public Url Provisioning Status CPU Memory Running Instance Registered Instance Persistent Storage ----------------- ---------- --------------- ----------------------- --------------------------------------------------- --------------------- ----- -------- ------------------ --------------------- -------------------- hellospring eastus <resource group> default Succeeded 1 2 1/1 0/1 -
Follow the tutorials listed below to learn more about Service Connector.
[!div class="nextstepaction"] Learn about Service Connector concepts