Labs: Introductio N To Spring 5 and Spring Mvc/Rest (Eclipse/Tom Cat)
Labs: Introductio N To Spring 5 and Spring Mvc/Rest (Eclipse/Tom Cat)
Labs: Introductio N To Spring 5 and Spring Mvc/Rest (Eclipse/Tom Cat)
INTRODUCTIO
N TO SPRING 5
AND SPRING
MVC/REST
(ECLIPSE/TOM
CAT)
RELEASE Lab
LEVEL
This manual has been tested with, and contains instructions
for, running the labs using the following platforms:
Introduction 2
Lab 1.1: Setting Up the Environment
Tasks to Perform
Note the different look of this instruction box compared to the
above
– Future labs will also use this format
NT
You'll need the lab setup file, with a name like
– LabSetup_Spring5-MVC-REST_2018050521.zip
Our base working directory (created when we extract the setup) is:
C:\StudentWork\Spring
– Assuming you extracted the zip to C:\ - otherwise adjust accordingly
– It includes a directory structure and files needed for the labs
Tasks to Perform
Make sure Java is installed
Make sure Eclipse is installed
Unzip the lab setup file to C:\
– This will create the directory structure, described in the next slide,
containing files that you will need for doing the labs
– You can unzip it elsewhere - just adjust all locations consistently
(1)
STRUCTURE
Root lab folder for this lab, already in your workspace is:
workspace\Lab01.1
–It contains starter files
• All labs either have starter files or build on a previous lab
–You'll create an Eclipse project in this folder
–Lab files and instructions are relative to the Lab01.1 folder
ECLIPSE OVERVIEW
Eclipse: Open source platform for building
integrated development environments (IDEs)
• Used mainly for Java development
• Can be flexibly extended via plugins to add capabilities
• http://www.eclipse.org is the main website
WHERE'S
Relax! THE
The projects PROJECTS?
will reveal themselves as we
proceed
– Do not import anything
LIBRARIES
Projects require Spring jars from the Spring distribution, plus
external dependencies (all supplied in the lab setup)
– We'll set up jars as an Eclipse user library for ease of use
– Labs before Spring Boot depend on these libraries being set up
– Later labs use maven for dependencies
Tasks to Perform
Go to Window | Preferences | Java | Build Path | User
Libraries
– Click New… , in the dialog, call the library Spring, and press
OK
– Click the Add External JARs… button, browse to
StudentWork\Spring\SpringLibraries
– Select all the jars in that folder, Click Open
– Select the Spring library again, click Add External JARs…,
browse to
StudentWork\Spring\SpringDependencies Lab 1.1: Setting up Environment 13
CREATE A PROJECT FOR
OUR
TasksAPPLICATION
to Perform
Create a Java Project (1)
– Call the project Lab01.1
• You MUST call it this to pick up
starter files
– Eclipse will then automatically set
the project folder to Lab01.1
• It already exists in the workspace
• Contains Java project for Eclipse
– Click Next
This will bring you to the Java
Settings dialog
– It should show the src and test
folders as source folders (2)
– It will also let us add a library
STOP
S
Overview: In this lab, we will:
– Become familiar with the different parts of basic Spring
– Create and use a Spring context to access a bean instance
– Write and run a simple Spring test
MODEL
Object Model: Our focus will be on the following types
– We'll cover more types shortly
– Note: Search methods in the catalog won't work yet
ON
The new lab folder where you will do all your work is:
workspace\Lab01.2
Tasks to Perform
Close all open files and projects
SPRING Tasks to Perform
Open CatalogImpl for editing
– The class is in the com.javatunes.service package, under
src
– Make sure CatalogImpl implements the Catalog interface
– Remember - we code to interfaces to decouple from a specific
implementation
– Save your changes
Run your test class again and check the results for errors
Lab 1.4: Dependency Injection 33
BREAK YOUR
PROGRAM AND TEST
IT Tasks to Perform
STOP
Lab 1.4: Dependency Injection 34