Skip to content

Lab 1: Setup and Component Scanning


In this lab, you'll download the project source code, check that all of the Spring Boot dependencies are downloaded, and explore how Spring does its component scanning.

Prepare & Clone

Verify Java Version

These labs require Java 11 or later. To verify that you have a supported version installed, type the following at a command-line:

java -version

You should see something like:

openjdk version "11.0.9" 2020-10-20 LTS
OpenJDK Runtime Environment Zulu11.43+21-CA (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM Zulu11.43+21-CA (build 11.0.9+11-LTS, mixed mode)

If you don't have 11 or later, you will need to install it.

Verify Maven Version

This project has Maven built in (using the Maven "Wrapper"). To check that it's working properly, type the following command:

./mvnw -version
mvnw.cmd -version

You should see output that looks something like:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/tedyoung/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3
Java version: 11.0.9, vendor: Azul Systems, Inc., runtime: /Users/tedyoung/.sdkman/candidates/java/11.0.9-zulu/zulu-11.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"

Clone Repository

You'll be given the link to the source code repository in class. Clone the repository to your local machine.

Maven Test

From the project's directory, run the following command:

./mvnw test
mvnw.cmd test

Maven will download the Spring Boot dependencies and run the tests. They should all pass, and you should see something like the following once it's done:

[INFO] Results:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.664 s
[INFO] Finished at: 2020-11-09T14:40:41-08:00
[INFO] ------------------------------------------------------------------------

Load into IDE

Load the project into your IDE and ensure that everything compiles and that you can run the CoffeeKioskApplicationTests test and that it passes.

Component Scanning

Run the CoffeeKioskApplication and watch the console output. If everything is working, you'll see the Spring Boot banner along with Spring's logging output.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v2.3.6.RELEASE)

Mixed in with the logging output, you'll see the results of System.out.println statements from the constructors for various classes.


What do you notice about the constructors that are called? e.g., what is the order in which the classes are instantiated?