This is a simple Java Spring Boot project where the user is able to login and view a list of orders that are retrieved from the database. Live demo here.
- Username & Password = Root
- Local Deployment --> http://localhost:8080 OR http://localhost:8080/login
- Heroku Cloud --> https://testapptopic4.herokuapp.com/login/
- Azure Cloud --> https://testapptopic4.azurewebsites.net/login/
- AWS Cloud --> http://cloudapp-env.eba-rc3u9bab.us-east-1.elasticbeanstalk.com
- Google Cloud --> https://cst323-testapp-14.uc.r.appspot.com
- Username & Password = Root
- Local Deployment --> http://localhost:8080 OR http://localhost:8080/login
- Heroku Cloud --> https://testapp-log.herokuapp.com
- Azure Cloud --> https://testapp-log.azurewebsites.net
- Demo Video: Video will be added shortly
- Heroku Cloud --> https://youtu.be/Id7sQe-8bqQ
- Azure Cloud --> https://youtu.be/u0ddZE-sIF0
- AWS Cloud --> https://youtu.be/7_Mtxpzn5KE
- Google Cloud --> https://youtu.be/Qrk_vMlynRE
- Version 1.0.0 - Azure Deployment
- Version 2.0.0 - Heroku Deployment
- Version 3.0.0 - Amazon Web Services Deployment
- Version 4.0.0 - Google Cloud Deployment
- Create a Microsoft Azure account.
- Go to the Azure marketplace and search for web app. Click create new web app service.
- On the create web app screen that appears validate that you have the correct Azure subscription. Click on a resource group or create a new one and give your app a unique name that will be displayed in the URL. Select Java 11 and Tomcat 8.5 for the Java web server stack. Click the windows OS option and select your desired location for the app to be deployed too. For example select the Central US region as your desired location.
- Click the Review + Create button.
- Once the app has been deployed pin it to your dashboard. Next, select the overview menu and click the project URL to open the application. Double check that the default Microsoft Azure Developer page is displayed. If you are able to view that default page you will also be able to access the phpMyAdmin in Azure.
- On the left menu scroll down to MySQL in app, enable the database, click save and run the app again (restart app). Go back to MySQL in app an click the manage app to display the phpMyAdmin Client page. Create a new database and import the DDL scripts from the local database via a CSV file.
- To get the DB credentials to configure your new app go to advanced tools and go to the debug console then click on CMD. Navigate to …\data\mysql directory and type in “Type MYSQLCONNSTR_localdb.txt” to view the Azure DB connection information. Save the DB connection info of the hostname, data source, user ID and password to a external text file for future reference.
- Update the JDBC string in the application.properties by switching to the new DB connection details found in the previous step. Also, add the parameter “?serverTimezone=UTC” at the end of the url line. Note if using Jasypt Encryptor set a secret named JASYPT_ENCRYPTOR_PASSWORD with your Jasper encryption key as a cloud platform environment variable.
- Create a Heroku account.
- Add a new file named Procfile to the root of the project.
- Do a local manual maven build.
- Test build at localhost:8080/ in the browser.
- Create a new “system.properties” file with the following line of code: “java.runtime.version=15”. Update the POM file to Java 15 version. In SpringToolsSuite4 click on the project so it’s highlighted then click the project tab and go to properties. Check what JRE version and switch to JavaSE-15 if not already on version 15.
- Connect local project to a new GitHub repository.
- Create a new project in Heroku using the GitHub deployment.
- Click new & create new app & give it a unique app name.
- On the projects page select deploy & select the GitHub deployment method.
- Search for the new GitHub repository, click search and select the repo.
- Go to project settings, click the add buildpack button, select Java and save the changes.
- Next, go to the resources on the projects page, then go to Add-ons and search for JawsDB SQL. Select JawsDB SQL, select the free plan called “Kitefin Shared”, and click the provision button.
- Connect the new JawsDB to MySQL Workbench. Click the JawsDB Add-on in Heroku and you will be able to view the database credentials to be added to MySQL Workbench. Export the DDL Scripts from MAMP for your local database to a CSV file format. Then go to the MySQL Workbench connection that was just created and click the new database that has 10 random characters. Click it, then click the import wizard to import the CSV file that was saved.
- Double check your MySQL JDBC driver in your POM.xml file is the same as the JawsDB MySQL one in Heroku. If not switch to the Jaws version.
- Update the Database connections for Spring Boot in the application.properties file.
- Create an Amazon Web Services (AWS) account.
- In the search bar (up top) search for
Elastic Beanstalk
and click it. - Click the orange
Create Application
button on the Elastic Beanstalk page.- Give the application a unique app name.
- Set the platform to
Java
and platform branch ofCorretto 11 running on 64bit Amazon Linux 2
. - Under the
Application code
section selectsample application
. - Next, click
configure more options
button. - Scroll down to the
Database
section and click edit.- Under
database settings
set engine tomysql
, engine version to your MySQL version your using locally. - Set instance class to db.t2.micro and set storage to 5 GB.
- Create a database username & password for the new database.
- Set availability to
low
. - Click the save database button.
- Under
- Click
create app
button at the bottom of the page. The creation of the application & environment will take 2-7 minutes to initialize.
- Your new environment for your application (project) page should appear and have a green health checkmark.
- In the Elastic Beanstalk menu on the left under the environment for your app called
[app name]-env
click on the configuration link. Scroll down to the database section and click the edit button. Click & open up the endpoint link which will redirect you to the ‘RDS Management Console’. Click on the newly created database (DB identifier).- IMPORTANT: Scroll down to the
Connectivity & Security
section and verify that Public accessibility is set to yes. - IMPORTANT: Take note of the Endpoint (hostname), port number, location (avaiability zone), database username/password, and the database name on the connectivity & security section.
- IMPORTANT: Scroll down to
Security group rules
section and click on theEC2 Security Group - Inbound
group. Next, scroll down and clickInbound rules
. Click the ‘Edit inbound rules’ button, then click theadd rule
button. Set type toall TCP
, source toAnywhere-IPv4
set to 0.0.0./0, then click the save rule button. - Create a connection to the AWS database by using MySQL Workbench using the database configurations (endpoint/hostname, username, password, port) from the
RDS Management Console
. Once successfully connected to the AWS database in MySQL Workbench run the DDL script to initialize the database. If your project is running locally you can export the DDL Scripts in SQL that can be imported as DDL scripts in workbench. - Update the database configurations within the Spring Boot project but navigating to the application.properties file and replacing the local database connection with the AWS configuration.
- Configure your project to Java 11 and execute a Maven build to create a JAR application.
- NOTE: In AWS Elastic Beanstalk uses the root path of “/” when executing health checks. If a home page isn’t defined then the application will fail the health check and show a severe error in the dashboard. Two solutions is to have a page for “/” or the endpoint in the controller can be changed to use a different path instead.
- IMPORTANT: Scroll down to the
- In the
Elastic Beanstalk
menu, go down to yourenvironment
and click onconfiguration
. Scroll down to environment properties and add the following variable then click theapply
button.- Name: SERVER_PORT
- Value: 5000
- In the
Elastic Beanstalk
menu, click the[APP NAME]-env
link under environments. Click theupload & deploy
button. Upload the Jar file (with updated AWS configurations from step 5e). Click deploy and wait for the changes to take place. - In the Elastic Beanstalk menu, go down and click
go to environment
link to access your web application.- NOTE: If the database queries are not working properly double check the database table name (upper/lower case) and AWS needs exact table names for proper queries.
- Your web application is now accessible in the cloud and connected to a MySQL database.
- Create Google Cloud account.
- NOTE: Google Cloud Platform requires a credit card and you are given a $300 credit over a 90 day period. Your card will not be charged as long as you follow the following steps and only make a micro database. I recommend deleting your Google Cloud account once you are done with your project to prevent getting charged in the future.
- Create a new App Engine project and application on Google Cloud by following the steps below:
- To the left of the search bar click where it says
my first project
and select createnew project
. - Give your project a
Name
then clickcreate
. - Once the App Engine welcome screen appears click
create application
. - Select a Region close to your location in the US and click next. This should take a few minutes to create the new app.
- To the left of the search bar click where it says
- Create a new MySQL Database using the steps below:
- In the top left click the 3 bars for the google cloud menu and click
SQL
. - Click the create instance button to create a cloud database.
- Choose the MySQL option. If you are prompted click
enable API
for the Compute Engine API. - Fill out the instance info for your new cloud database by entering a instance ID (database name), root password, desired database version for MySQL that matches the local MySQL version or close to it. Select
single zone
for zonal availability. - Click
show configuration options
to change advanced database settings.- Select machine type and set to lightweight for 1 vCPU, 3.75 GB.
- Set storage to 20 GB.
- Make sure Public IP is checked under connections.
- Click create database instance.
- Take note of your Public IP Address for the instance that was just created.
- From the left menu select the users option, click
add new user
account. Give the instance (database) a username/password [DB_USERNAME]/[DB_PASSWORD] and set host name to allowany host
. Click theadd
button to create a new instance account. - Next, select the databases option on the left pane and create a new database (your schema). Give your database a name then click create.
- To find your public IP address go to a new tab in the web browser and search
my IP
. Take note of your IPv4 Address for the next step. - Next, select the connections option on the left pane and under
Authorization Networks
clickadd network
. Set name to GCU, network to your Public IP address (from previous step), click thedone
andsave
button. - The database updates and changes can take a few minutes to be fully implemented.
- Next, setup a MySQL Workbench database connection to the Google Cloud instance that was just created using the database IP address listed and your database credentials that were given when you created a new user.
- Connect to the database in MySQL Workbench and run your DDL scripts.
- In the top left click the 3 bars for the main Google Cloud menu and click
APIs & Services
, then clicklibrary
option. While on the API Library page search forGoogle Cloud SQL
andCloud SQL Admin API
, and make sure they are both enabled.
- In the top left click the 3 bars for the google cloud menu and click
- Before we deploy our Spring Boot test app we need to configure, build, test then we will be able to deploy.
- In the top left next to the notification/info button click the Cloud Shell and activate it.
- Run the following command in the Cloud Shell to clone the Github repository for the test app.
- NOTE: Double check the JRE System Library is set to Java 11 before cloning the project.
- git clone [URL to your Test App Repository]
- NOTE: If not public set it to public for the clone to take place and then you can make the repo private again.
- Click on
open editor
to update the following changes in the application.- Set Maven to build using Java 11.
- Add the following Maven dependencies (should be the last dependencies). Double check that these dependencies haven’t been declared earlier in the pom.xml file.
- At the bottom of the pom.xml add the following Maven build plugin after the spring framework plugin.
- Create a new directory in your project in the Cloud Shell named
appengine
under src/main. Create a file within src/main/appengine named app.yaml with the exact following entries: - Update the application.properties file with the MySQL Database connection configuration (JDBC Connection string, database username, and database password).
- In the top left next to the notification/info button click the Cloud Shell and activate it.
- Test the configuration changes to the project by navigating to the root of the project then use the following commands.
- mvn clean package
- NOTE: May run into duplicate dependencies declared in the pom file or database table name is incorrect. Table names and columns need to match the code in the SQL queries.
- cd target
- java -jar [JAR NAME]
- Make sure that there are no errors on startup or when executing the clean package command.
- To test click the web preview icon in the Shell and use port 8080 to view the cloud project locally before deploying.
- mvn clean package
- Deploy in the cloud shell by navigating back to the root of the project and run the following command:
- mvn clean package appengine:deploy
- NOTE: This will take about 4-10 minutes to complete. If this fails you make need to wait for Google to finish provisioning storage to upload your build artifact. If the deployment does fail try deployment command multiple time and sometimes the clean package will fix some issues that may be occurring.
- mvn clean package appengine:deploy
- Test the web application by going to the target URL in the Cloud Shell terminal to see if you are able to view the website and see if the database is connected properly.