Lab 3.1: Hello Boot World: in This Lab, You Will Configure and Run A Simple Spring Boot Job
Lab 3.1: Hello Boot World: in This Lab, You Will Configure and Run A Simple Spring Boot Job
S
Overview: In this lab, we will become familiar with Spring
Boot and run a simple application that uses it
– We'll provide all of the code and configuration
– You will just run it, and examine how Spring Boot works
– You will use maven and Eclipse to work with it
– You'll also become familiar with the maven-based project
structure
PROJECT
Eclipse INTO
understands maven ECLIPSE
projects fairly well
– The starter files (e.g. pom.xml, and Java source) are supplied by us
– When importing, Eclipse examines pom.xml, and sets up the classpath
– It understands maven's project structure, and sets up the Eclipse project
– It will compile the source as normal when importing (or changing source)
• No need to use maven for a compile or program execution- Eclipse does it
Tasks to Perform
Import the Lab03.1 project into Eclipse as follows:
If you see this error, follow the instructions on the next slide
– See notes on this page if you can't get maven to work any way at all (1)
If you do NOT see such an error, then skip the next slide
– It indicates you can reach the maven repositories
Go to your home folder (1), and find a folder named .m2 ("dot"m2)
– If it exists, rename that folder to .m2-ORIG (2)
– If it doesn't exist, that's no problem, just continue below (but read the note)
Copy the .m2 folder in StudentWork\Spring\mavenRepository
– Paste it to your home folder
– That's it - you've got a local maven repo with all the jars you need
Update the Lab03.1 project - Right Click | maven | Update Project
– The error should now go away - your maven repo is set up
Remember to restore your original .m2 folder after the course
– Rename the .m2 lab repo to .m2-Spring, and rename .m2-ORIG to .m2
Lab 3.1: Hello Boot World 5
REVIEW THE Lab
PROJECT POM
Tasks to Perform
Within Eclipse, open pom.xml for review
– First view the straight source (pom.xml tab)
– The Dependency Hierarchy tab shows direct/indirect dependencies
OUTPUT Tasks to Perform
Spring Boot has copious debugging built in
– Open src/main/resources/application.properties, set boot logging to debug
logging.level.org.springframework.boot=debug
– Rerun - this prints out a lot of info - e.g. the auto-configuration (see below)
JAR Tasks to Perform
We will package the project with maven from within Eclipse (1)
REPOSITORIES
We've occasionally seen odd errors in maven projects with
Eclipse
– Either compile or runtime
– Hard to track, and hard to figure out where they come from