Last Updated: 10-02-2022

Status: Draft

Overview

In this document, we will cover how to deploy a Springboot project on Azure Cloud.

Note that a limitation of deploying to Azure is that the Springboot project must be compiled on either Java version 8 or 11 only.

It is important to stop your resources when not in use, or delete them when you no longer need them, as Microsoft will continue to bill you if the resources are still running or taking up space.

Java Version

The JRE of the Springboot needs to be either Java version 8 or 11. To check what version you have installed, go to C:\Program Files\Java .

You can download either version here if you do not have it installed: https://www.oracle.com/java/technologies/downloads/archive/

To change the Java version, see steps below:

  1. Right-click on the project, select Properties
  2. In the panel that appears, select Java Compiler

  1. If the Java version is NOT 1.8(This is the same as Java 8) or 11, then uncheck the Use compliance....
  2. Select either Java 1.8 or 11
  3. Click Apply and Close.
  4. Check that the project JRE has changed to the appropriate version

  1. Visit https://azure.microsoft.com/en-us/free/students/and click the button [ Activate Now > ].
  2. Sign in using your RP account 19NNNNNN@myrp.edu.sg and password. You will be presented a page where you can enter your personal particulars.
  3. Do the following data inputs under About you
  1. Country/Region: Select Singapore.
  2. First name:
  3. Last name:
  4. Email address: Enter the same RP email address in Step 2
  5. Phone: Enter your 8 digit mobile phone
  6. Click on the button [ Next ]
  1. Do the following data inputs under Agreement
  1. Check the two check boxes.
  2. Click on the button [ Sign up ]
  1. You will be redirected the Welcome to Microsoft Azure page. Click on the button [ Maybe later ].
  1. From the menu at the top-right corner, click Home
  2. Click and you should see a new subscription created for you.

  1. Once logged into Azure portal, you will see the screenshot similar to below.

The domain of the requested iframe (lh6.googleusercontent.com) has not been whitelisted.

  1. Click Create a resource

  1. In the Create a resource page, enter Azure Spring Cloud in the search bar and select Azure Spring Cloud.

  1. Click Create

  1. In the configurations that comes up in Project Details,
  1. Under Subscription, select Azure for Students
  2. Under Resource group, click Create new and enter c372 as the Name, click OK

(If the name is not available, include your student ID)

The domain of the requested iframe (lh3.googleusercontent.com) has not been whitelisted.

6. In Service Details,

  1. Under Name, enter c372projects

(If the name is not available, include your student ID)

  1. Under Region, select East US

The domain of the requested iframe (lh6.googleusercontent.com) has not been whitelisted.

7. Click Review and Create

The domain of the requested iframe (lh6.googleusercontent.com) has not been whitelisted.

8. The resource group will take a while to be created and deployed. You will receive a notification once it is done.

The domain of the requested iframe (lh5.googleusercontent.com) has not been whitelisted.

9. Once completed, you should see this a similar screen to below.

The domain of the requested iframe (lh4.googleusercontent.com) has not been whitelisted.

Note: In this page, you can also delete the instance when not in use.

  1. Go back to Azure portal homepage.

The domain of the requested iframe (lh6.googleusercontent.com) has not been whitelisted.

  1. Click Create a resource

  1. In the Create a resource page, enter Mysql in the search bar and select Azure Database for MySQL

The domain of the requested iframe (lh5.googleusercontent.com) has not been whitelisted.

  1. Click Create

The domain of the requested iframe (lh3.googleusercontent.com) has not been whitelisted.

  1. In the page below, select Create for the Flexible server

The domain of the requested iframe (lh3.googleusercontent.com) has not been whitelisted.

  1. In the Basics tab, in Project Details,
  1. Under Subscription, select Azure for Students
  2. Under Resource group, select c372

7. In the Basics tab, in Server Details,

  1. Under Server name, enter c372mysql

(If the name is not available, include your student ID)

  1. Under Region, select East US
  2. Under Workload type, select Development
  3. Under Compute + storage, leave it if it is similar to the screenshot. Otherwise, click on configure server to select the lowest setting.
  4. Under Availability, leave it as No preference
  5. Under MySQL version, select 5.7 (Note, we are not using version 8 as workbench will only work with version 5)

8. In the Basics tab, in High Availability and Administrator account:

  1. Do not check Enable high availability
  2. Create an admin username and password. (Note this down)

9. In the Networking tab,

  1. Under Network connectivity, select Public access
  2. Under Firewall rules, check Allow public access ....
  3. Under Firewall rules, click Add current client IP

10. Click Review and create

11. After the settings are validated, click Create

12. Creation and Deployment of the database will take a while. You will receive a notification once deployed.

13. Once deployed, go to the database resource to get the server name. Do make a note of it as you will need to use it later.

Note: In this page you can stop or delete the database when not in use

14. Start MySQL Workbench, click on the + symbol to create a new connection

15. Enter connection details similar as shown.

  1. Under Hostname, use the database hostname from step 13
  2. Under username, use the username that you set.
  3. The password will be prompted

16. Click Test Connection to check that the connection works. (Note, this may not work if using RP network)

17. Click OK

18. You can use workbench as per how you normally do it.

19. Create a database named c372 (Or the same name as you use in the local MySQL)

In pom.xml, you should remove dependencies that are not required when deploying to reduce the size of the upload. For e.g. spring-boot-devtools is only helpful during development.

  1. In application.properties, you will need to update the mysql database host.
  2. Comment the existing configurations for mysql.

Note:

Before you start this section, you will need to:

  1. Start Windows PowerShell and change directory to your project folder.
  1. To find your project folder, in Eclipse, right click on the project, select Properties
  2. You will see the location of your code, copy that location
  3. Use the cd command in PowerShell to change directory to that folder
  1. In PowerShell, ensure that you are inside the project folder and type the following command to package the project into a JAR file:

mvn clean package -DskipTests

  1. In Eclipse, refresh your project, you should see the JAR file created.

Note the name of the JAR file as you will need to use it later.

  1. In Powershell, login to azure by executing the command:

az login

  1. You will be prompted to login on a web browser, use the same login details as you do for the Azure Portal.
  1. Once logged in, you will see the output similar to below:

The domain of the requested iframe (lh4.googleusercontent.com) has not been whitelisted.

  1. To create an app, use the command below:

az spring-cloud app create -n -s -g --assign-endpoint true --runtime-version=Java_11

Note:

  1. To deploy the app, use the command below:

az spring-cloud app deploy -n -s -g --artifact-path target/ --verbose

Note:

  1. To check the logs in case of any issue, use the command:

az spring-cloud app logs - -s -g

Note:

  1. Once deployed, go to the Azure spring cloud service you created, select Apps. You should see the app you created there.

  1. Click on the app you created
  1. Click on the URL generated

Note: In this page, you can also stop or delete the instance when not in use.

It is important to stop your resources when not in use, or delete them when you no longer need them, as Microsoft will continue to bill you if the resources are still running or taking up space.

To easily delete everything, you can go to the resource group that you have grouped your resources under, and click Delete resource group. All related resources will be deleted.