lab06 : Getting Started with Spring Boot Webapps

num ready? description assigned due
lab06 true Getting Started with Spring Boot Webapps Thu 11/01 05:00PM Fri 11/09 11:59PM

Previously, in lab03, you worked with a small Hello, World app based on a web technology known as SparkJava.

We learned a few concepts there, such as:

We are now going to turn to a different Java web framework, one called Spring Boot.

Spring Boot is:

We’ll start by putting up a simple Hello World app, and then a little at a time, we’ll add some features to that app, documenting as we go.

Step 0: Choose to work alone, in a pair, or in a trio

You may work alone, in a pair, or in a trio (group of three), but if you work with others, please work with others that are IN THE SAME ROW, IN THE SAME SECTION, assigned to the same mentor as you.

Step 1: If you are working on your own machine

You can skip this step if:

Otherwise, visit the page for lab03 and follow the instructions under Step 0 to

Step 2: Create a repo

Create an empty project repo under the ucsb-cs56-f18 github organization

Choose the name based on your githubid, or if working in a pair or trio, based on the combination of your github ids:

If working like this Create a repo with this name
Alone lab06-githubid
In a pair lab06-githubid1-githubid2 (put githubid1 and githubid2 in alphabetical order
In a group of three lab06-githubid1-githubid2-githubid3 (put githubid1, githubid2 and githubid3 in alphabetical order

Step 3: Add pair or trio partners as collaborators

Whoever creates the repo should add the other pair/trio members as collaborators on Github.

Step 4: Clone repo and pull in starter code

The starter code for this assignment is in https://github.com/ucsb-cs56-f18/STARTER_lab06

To add that as a remote:

git remote add starter https://github.com/ucsb-cs56-f18/STARTER_lab06

Then do:

git pull starter master
git push origin master

Then try runnning the starter code with:

mvn spring-boot:run

It should bring up a running webapp on http://localhost:8080.

If so, you are ready for the next step.

Step 5: Choose a web app and document your choice

Now, choose one of the webapps described at that link below, or come up with your own idea for a webapp.

Then:

Step 6: Modify the nav bar, and the placeholder pages

You are now going to imagine that you have built a “minimum viable product” for the webapp that you chose.

Imagine what the navigation bar of that app looks like.

Now modify the code:

On this page, the user will be able to enter the name of a city they want to visit, and press “find coffee shops”. The page will then show a list of all the coffee shops in that city.

OR:

On this page, the user will enter all of the courses they still need to take in order to graduate. Those courses will then be stored in the database so that they are there the next time the users logs in.

Iterate on this until the navigation bar has a set of options, and a set of placeholder pages that, if you implemented all of them with the functionality described, would be a reasonably good start at the webapp proposed.

Step 7: Login to Heroku

If you didn’t already create a Heroku account on the free plan, do so now. There is additional information in the instructions for lab03.

Then, at the command prompt, use this command to login to Heroku:

heroku login

Additionally, open a web browser window and login to heroku at https://dashboard.heroku.com.

Step 8: Create a new Heroku App using the Heroku CLI

Logged into CSIL (or one of the machines in the CSTL, i.e. Phelps 3525), use this command to login to Heroku at the command line:

heroku login

Then, use this command to create a new web app running on heroku. Substitute your github id (or pair or trio of githubids) in place of githubid. Note that you should convert your githubid to all lowercase; heroku web-app names do not permit uppercase letters.

For a pair or trio, if including all of your githubid results in a project name that is too long for Heroku, you may substitute initials, e.g. lab06_rw_pc_dm rather than lab06_richertwang_pconrad_dibamirza

Note: please do not literally put the letters githubid in your app name; you are meant to substitute your own github id there.

heroku create cs56-f18-githubid-lab06

Step 9: Modify the pom.xml file to refer to your heroku app

In the pom.xml file, find the <plugins> element. Add the following <plugin> somewhere inside the <plugins> element.

  <plugin>
	<groupId>com.heroku.sdk</groupId>
	<artifactId>heroku-maven-plugin</artifactId>
	<version>2.0.3</version>
	<configuration>
          <jdkVersion>1.8</jdkVersion>
          <!-- Use your own application name -->
	  <!-- at Heroku CLI, use heroku apps to list, or use Heroku Dashboard -->
          <appName>ucsb-cs56-pconrad-08-28-18</appName> 
          <processTypes>
            <!-- Tell Heroku how to launch your application -->
            <!-- You might have to remove the ./ in front   -->
            <web>java $JAVA_OPTS -jar target/gs-spring-boot-0.1.0.jar --server.port=$PORT</web>

          </processTypes>
	</configuration>
   </plugin>

The line you need to change is the one that says:

 <appName>ucsb-cs56-pconrad-08-28-18</appName> 

Change this to the name of your heroku app. If you’ve forgotten it, you can locate it either by typing:

heroku apps

or by logging into the Heroku Dashboard in a web browser at https://dashboard.heroku.com/apps

Then, type the following to deploy your web app to Heroku:

mvn package heroku:deploy

You should see a lot of output. At the end of this output, you should see something like this:

...
[INFO] remote: -----> heroku-maven-plugin app detected
[INFO] remote: -----> Installing JDK 1.8... done
[INFO] remote: -----> Discovering process types
[INFO] remote:        Procfile declares types -> web
[INFO] remote: 
[INFO] remote: -----> Compressing...
[INFO] remote:        Done: 54M
[INFO] remote: -----> Launching...
[INFO] remote:        Released v10
[INFO] remote:        https://ucsb-cs56-pconrad-08-28-18.herokuapp.com/ deployed to Heroku
[INFO] remote: 
[INFO] -----> Done
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.539 s
[INFO] Finished at: 2018-08-31T01:56:14-07:00
[INFO] Final Memory: 29M/268M
[INFO] ------------------------------------------------------------------------

The line that you are looking for is this one:

[INFO] remote:        https://ucsb-cs56-pconrad-08-28-18.herokuapp.com/ deployed to Heroku

That is the URL where you should now be able to see your webapp running. This URL should be accessible from any web browser connected to the internet.

What if it doesn’t work?

If it doesn’t work, try these things before asking a mentor, TA, or instructor for help.

  1. Make sure you are logged into Heroku at CLI with heroku login. If you exited your CSIL shell (logged out) and logged back in again, you have to login to Heroku again. Then repeat the commands.
  2. Try, try running heroku apps. Make sure the <appname>app-name-goes-here</appname> element in the heroku-maven-plugin section of your pom.xml matches the name of your heroku app exactly.
  3. If it does, try heroku logs --app appname (substitute the name of your app where you see appname). You’ll see the log output of that app on Heroku.
    • You may find it helpful to open a second Terminal, login to CSIL and the Heroku CLI, and use heroku logs --app appname --tail, which keeps the log output running continously.
    • You can also see your logs in a web browser at: https://dashboard.heroku.com/apps/app-name/logs (note that you need to put your app-name in the URL instead of app-name.
    • You can navigate to this from https://dashboard.heroku.com/ by selecting your app, clicking on it, selecting the More menu at upper right, and the selecting Logs.

Step 10: Submitting your work for grading

When you have a running web app, visit https://gauchospace.ucsb.edu/courses/mod/assign/view.php?id=1639566 and make a submission.

In the text area, enter something like this, substituting your repo name and your Heroku app name:

repo name: https://github.com/chrislee123/lab06-chrislee123
on heroku: https://cs56-f18-chrislee123-lab06.herokuapp.com

Then, and this is super important, please make both of those URLs clickable urls.

The instructions for doing so are here: https://ucsb-cs56-pconrad.github.io/topics/gauchospace_clickable_urls/