📺 Develpreneur YouTube Episode

Video + transcript

Spring Boot Getting Started - Add URLS and End Points.

2023-11-16 •Youtube

Detailed Notes

We are continuing a series of tutorials focused on Spring Boot. The crux of the project is to convert/migrate an old JSP/Tomcat application to a modern Spring Boot application and Java 7/8 to a current version. This episode focuses on turning your application into something more than a home page and adding some endpoints.

You can learn more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list, and you will periodically receive coupons for courses and notifications of the latest releases.

Transcript Text
[Music]
well hello and welcome back we are
continue playing around with spring boot
last time around we got our server
running and what we're going to do this
time is we're going to add a little bit
of there uh a couple things just to sort
of be some cool stuff to add to us we're
going to go in
here to let's see where it's
at there we go in Ops uh so we're going
to go on Ops we're going to do the
spring boot
actuator uh actually let's do the admin
as well but for right now we're going to
work on that so we're going to come back
in as we did before uh yes we can take
all of that we're going to finish
anyways and then we're going to here
it's building let's see if it's going to
work I think we got all of our new
stuff and so now we should have yeah
[Music]
uh should see some new end points in
here let's do a job let's do a may an
update just to
be safe it's always good make sure we
get that rebuild it okay so now we
should be able to go to with our
actuator
wh if I can stop doing a drag and
drop now if we go out to our 8080
Port I do
actuator then whoops wrong one
we want to do
actuator SL Health
sorry oh it doesn't like that okay one
of the things I did is I added Dev tools
and that blew this up a little bit so
pulling that back out now when we run we
will note which was something I was
looking for is we've got an extra
actuator
endpoint and now we can do this and we
can see some information about our site
so we can do like actuator
Health it doesn't it's not the most
awesome but we can see hey status is up
we can do shut down uh more importantly
like this we can just do some stuff to
get some very basic things about our
site and here's our end point so we can
see you know health for a path uh
templated blah blah blah there you go so
and it shows that you can also do a
shutdown
actuator shut
down and actually doesn't like that
these days shutdown half has to be from
the uh properties
though so here I do
management
inpoint
who you see a bunch of these here
inpoint Dot
shut
down startup enabled here is shut down
enabled equals
true and then I'm going to see that I'm
going to get
this that means I also need who let's
put this
here
management. inp
points there we go
Ino web.
exposure do
include Health comma info comma show
down and let's just do let's see if I've
got
inpo Health
enabled
true and let's
do uh info there we go whoops just saw
it info enabled equals
true
all right so now should get something a
little differently so if we come in here
let's do we did
Health should still give us the same
thing should do
info which gives us nothing terribly
useful and if we do shut
down boom then we got an issue for that
because it didn't like oh because it's a
git didn't like
that
which is okay so just a few things there
let's just go ahead and take that down
so we've got actually which is a nice
way for us now that I've cleaned it up
is to at least have some things where we
can actually check on our site
periodically whether it's something like
this or whether it's just go with the uh
Health hope I typed it right yeah and so
you can see status out so these are a
few things just like
builtins that you can work with so now
let's dive in a little bit more we did
very very basic uh controller and you
know hello world sort of thing last time
this time around it get a little more
complicated so let's start with let's
create a new
one and get a little deeper into this so
this is going to be
greet and it's going to be
greet this time we're we going to
actually give it
something so we're going to use a
request
param and we're going to say we're going
to give him a
name name so now you've got a request
preter name it's going to be
required uh we're going to say not right
now and we're going to give it a default
value um uh
default if I can type right which I'm
really struggling with and so our
default value is going to be
Sam and let's see so there let's make
sure I've got my things right here so
that string
name Comm
model
model uh let's see if I can get those
picked up
it is going to be the UI
model there we go so I've got those
loaded
in and I'm going to do model
that attribute oh
sorry add
attribute and I'm going to take the name
I'm going to add it to the model
just cuz and I'm going to
return yeah no I'm going to make a
lowercase because now what it's going to
do is it's going to go look for
greetings. HTML and it's going to look
for that in Source main resources
templates so what I need to do is create
a new
file this is going to be
greetings
HTML
and so now in here what I can do uh let
me do my doc
type
HTML get your basic HTML crap going
here my
body
title this will be
um spring boot
greeting and then in the body I'm going
to do I'm going to do it in an
H2
and now we do this little bit so the so
what we're going to do is we're going to
do something very simple uh let's
see
greetings
to uh dollar dollar
dollar let give be
name
I'm just going to do it like that very
very simple so now it's going to come in
it's just going to do a replace based on
our model here so we've got that
name if we run
it uh what did we call this we call this
greet so uh if we come in here run run
run run run as a spring boot
app
oops
uh I've already got somebody running
that so let
me kill that okay let's try that again
well let's
see okay so now it should run if we go
to our Local
Host 8080 go check this sucker out there
we go if we go to greet
it's going to say
Greetings oh
because probably didn't set that up
right oh here's our problem
um this is going to be a straight that
was a r that one wasn't going to try to
do anything so now it's going to give us
some really funky stuff because now it's
going to try to control do this stuff a
little bit differently so watch we're
just going to break the older one
uh I don't need RIS controller at all
actually
um yeah we're just going to do this so
we're going to get rid
of uh this is going to be it's not that
anymore this going to be a
stereotype we don't need that controller
controller um those things are going to
be broken probably it's not going to
like
those but
now y let's go see oh did we not stop it
we probably didn't rebuild
it let's run
it there we go and so now it's not
sending across so we're got to go figure
out why it's not sending that now if we
do like just the slash it's going to
give us something it's going to say
can't find it probably yep can't find
the
page so we're going to want to get rid
of
these and now what we need to do is uh
let's see let's do
system.out print
[Music]
line
name so first thing we do is come
through here let's just do a
greet so if we do a normal one we're
going to get somewhere in
here oh we need a
template which means we need this to be
this is actually an important piece XML
in nam space
equals
www. time
lef.org
this should give us something a little
bit
better let's see if it's going to give
us that this time um
stop
run
see what it's going to give us this
time yep so there's the name
Sam if I
do uh name
equals
Bob then I've got that coming through so
now what I need to do is on greetings
got it right
HTML okay so one of the things we need
to do is we do need to make sure that we
reload a page when we do it uh that can
cause us some problems and so once we
reload this sucker then we do get
greetings Bob or if we don't send
anything greetings Sam so now we've got
very basic where we have a page we can
spit some information out to it based on
what is
sent and uh we can actually we've got a
model now that we can work with within
the page so we're going to come back
next time
around and we're going to continue
working on this we're going to get a
little more complicated uh we're going
to start adding adding some pages and
stuff like that and uh see how it looks
and sort of start building out a you
know basic navigation for app but that's
it for now we've got a we've got spring
boot we've got something going on we're
using instead of the rest controller
that we had before that we could have
used for a um for example for an API or
something like that that we have our
actual controller which is more of a web
controller and we'll just uh continue
chugging along on this actually what I'm
going to do is I'm going to actually
give myself a second controller real
quick uh I'm going to
do I do hello rest
controller and this guy instead let's
get rid of him let's get him back a
little
bit before we did the
Greet
there we
go so if we take
that don't need that don't save because
we don't want to break what we had we're
now going to go to the rest controller
and do it like
that we going to call him
hello rest
controller there we go
and so now let's make sure we got that
we got hello controller so now if we
stop and
start we have two different controllers
floating around depending on what we do
so greet works the
same otherwise we get our rest
controller so now we've got both running
off the same there we go that being said
we'll come back to it next time we're
continue to add to our application so go
out there and have yourself a great day
a great week and we will talk to you
next
time well hello this is Rob from develop
or building better developers and we
have a mastermind class that will be
starting or actually several Mastermind
classes starting in 2024 check us out at
technology mastermind2 24.com we've got
all the information you need including
some pricing early bird discounts up to
50% off but those are things that you're
going to have to act soon there is an
application process so go ahead and sign
up today thanks a lot
[Music]
Transcript Segments
1.35

[Music]

27.24

well hello and welcome back we are

28.96

continue playing around with spring boot

32.559

last time around we got our server

34.32

running and what we're going to do this

36.32

time is we're going to add a little bit

38.079

of there uh a couple things just to sort

40.719

of be some cool stuff to add to us we're

43.879

going to go in

46.28

here to let's see where it's

51.52

at there we go in Ops uh so we're going

54.84

to go on Ops we're going to do the

55.84

spring boot

58.199

actuator uh actually let's do the admin

60.559

as well but for right now we're going to

62.199

work on that so we're going to come back

63.359

in as we did before uh yes we can take

66.36

all of that we're going to finish

70.56

anyways and then we're going to here

73.24

it's building let's see if it's going to

75.08

work I think we got all of our new

78.96

stuff and so now we should have yeah

82.96

[Music]

84.2

uh should see some new end points in

87.56

here let's do a job let's do a may an

90.479

update just to

94.28

be safe it's always good make sure we

98.64

get that rebuild it okay so now we

101.96

should be able to go to with our

103.759

actuator

105.92

wh if I can stop doing a drag and

109.68

drop now if we go out to our 8080

113.439

Port I do

117.119

actuator then whoops wrong one

123.119

we want to do

124.719

actuator SL Health

128.959

sorry oh it doesn't like that okay one

131.959

of the things I did is I added Dev tools

133.76

and that blew this up a little bit so

136.48

pulling that back out now when we run we

138.879

will note which was something I was

140.319

looking for is we've got an extra

142.16

actuator

143.68

endpoint and now we can do this and we

145.959

can see some information about our site

148.16

so we can do like actuator

150.599

Health it doesn't it's not the most

152.48

awesome but we can see hey status is up

154.44

we can do shut down uh more importantly

157.12

like this we can just do some stuff to

158.64

get some very basic things about our

161.8

site and here's our end point so we can

164.4

see you know health for a path uh

167.92

templated blah blah blah there you go so

171.28

and it shows that you can also do a

173.56

shutdown

176.28

actuator shut

178.76

down and actually doesn't like that

181.28

these days shutdown half has to be from

186.519

the uh properties

193.879

though so here I do

200.08

management

202.36

inpoint

204.4

who you see a bunch of these here

207.2

inpoint Dot

211.319

shut

215.319

down startup enabled here is shut down

222.68

enabled equals

231.04

true and then I'm going to see that I'm

233.2

going to get

236.599

this that means I also need who let's

240

put this

241.56

here

244

management. inp

249.12

points there we go

255.919

Ino web.

261.12

exposure do

266.32

include Health comma info comma show

272

down and let's just do let's see if I've

276.919

got

281.88

inpo Health

285.199

enabled

289.4

true and let's

293.88

do uh info there we go whoops just saw

296.56

it info enabled equals

298.56

true

300.16

all right so now should get something a

302.479

little differently so if we come in here

305.32

let's do we did

307.56

Health should still give us the same

310.36

thing should do

313.96

info which gives us nothing terribly

316.759

useful and if we do shut

320.68

down boom then we got an issue for that

323.759

because it didn't like oh because it's a

325.88

git didn't like

328.479

that

331.88

which is okay so just a few things there

334.88

let's just go ahead and take that down

337.12

so we've got actually which is a nice

338.68

way for us now that I've cleaned it up

341.4

is to at least have some things where we

342.8

can actually check on our site

344.639

periodically whether it's something like

346.44

this or whether it's just go with the uh

351.56

Health hope I typed it right yeah and so

354.039

you can see status out so these are a

355.199

few things just like

357.08

builtins that you can work with so now

360.319

let's dive in a little bit more we did

362.319

very very basic uh controller and you

366.919

know hello world sort of thing last time

369.88

this time around it get a little more

372.68

complicated so let's start with let's

375.28

create a new

377.8

one and get a little deeper into this so

380.24

this is going to be

383.96

greet and it's going to be

387.599

greet this time we're we going to

389.759

actually give it

391.199

something so we're going to use a

394.319

request

400.96

param and we're going to say we're going

403.44

to give him a

407.88

name name so now you've got a request

410.28

preter name it's going to be

412.96

required uh we're going to say not right

416.36

now and we're going to give it a default

418.4

value um uh

422.039

default if I can type right which I'm

424.919

really struggling with and so our

427.12

default value is going to be

431.599

Sam and let's see so there let's make

434.28

sure I've got my things right here so

436.759

that string

442.08

name Comm

444.759

model

446.72

model uh let's see if I can get those

448.72

picked up

451.08

it is going to be the UI

454.759

model there we go so I've got those

457.12

loaded

461.16

in and I'm going to do model

465.68

that attribute oh

469.28

sorry add

475.72

attribute and I'm going to take the name

477.84

I'm going to add it to the model

481.12

just cuz and I'm going to

484.4

return yeah no I'm going to make a

486.8

lowercase because now what it's going to

488.639

do is it's going to go look for

491.479

greetings. HTML and it's going to look

494.599

for that in Source main resources

498.12

templates so what I need to do is create

501.28

a new

502.4

file this is going to be

506.039

greetings

508.24

HTML

511.12

and so now in here what I can do uh let

513.959

me do my doc

515.719

type

517.399

HTML get your basic HTML crap going

532.8

here my

538.2

body

542.6

title this will be

546.32

um spring boot

552.64

greeting and then in the body I'm going

554.88

to do I'm going to do it in an

568.12

H2

577.279

and now we do this little bit so the so

581.64

what we're going to do is we're going to

582.56

do something very simple uh let's

584.72

see

588.32

greetings

590.8

to uh dollar dollar

593.72

dollar let give be

598.12

name

599.92

I'm just going to do it like that very

601.6

very simple so now it's going to come in

604.68

it's just going to do a replace based on

606.519

our model here so we've got that

610.68

name if we run

613.36

it uh what did we call this we call this

617.12

greet so uh if we come in here run run

621.399

run run run as a spring boot

628.04

app

630.48

oops

632.839

uh I've already got somebody running

635.04

that so let

639.48

me kill that okay let's try that again

642.72

well let's

648.36

see okay so now it should run if we go

651.72

to our Local

653.72

Host 8080 go check this sucker out there

657.32

we go if we go to greet

662.12

it's going to say

663.639

Greetings oh

666.72

because probably didn't set that up

670.12

right oh here's our problem

675.24

um this is going to be a straight that

677.48

was a r that one wasn't going to try to

679.44

do anything so now it's going to give us

680.519

some really funky stuff because now it's

683.399

going to try to control do this stuff a

685.44

little bit differently so watch we're

687.8

just going to break the older one

692.24

uh I don't need RIS controller at all

695.839

actually

699.639

um yeah we're just going to do this so

701.92

we're going to get rid

706.76

of uh this is going to be it's not that

709.76

anymore this going to be a

717.16

stereotype we don't need that controller

720.079

controller um those things are going to

722.48

be broken probably it's not going to

724.04

like

725.6

those but

731.04

now y let's go see oh did we not stop it

734

we probably didn't rebuild

738.279

it let's run

746.639

it there we go and so now it's not

749.76

sending across so we're got to go figure

751.16

out why it's not sending that now if we

753.32

do like just the slash it's going to

755

give us something it's going to say

756.199

can't find it probably yep can't find

758.56

the

759.279

page so we're going to want to get rid

761.44

of

764.92

these and now what we need to do is uh

768.76

let's see let's do

774

system.out print

775.45

[Music]

777.839

line

780.56

name so first thing we do is come

783.24

through here let's just do a

786.6

greet so if we do a normal one we're

789.279

going to get somewhere in

798.199

here oh we need a

804.76

template which means we need this to be

808.32

this is actually an important piece XML

811.279

in nam space

815.88

equals

817.8

www. time

822.079

lef.org

825.079

this should give us something a little

826.959

bit

828.8

better let's see if it's going to give

830.8

us that this time um

835.839

stop

837.759

run

840.639

see what it's going to give us this

845.8

time yep so there's the name

849.399

Sam if I

854.32

do uh name

856.759

equals

859.56

Bob then I've got that coming through so

861.92

now what I need to do is on greetings

864.12

got it right

865.959

HTML okay so one of the things we need

868.16

to do is we do need to make sure that we

870.279

reload a page when we do it uh that can

873.24

cause us some problems and so once we

877.199

reload this sucker then we do get

879.8

greetings Bob or if we don't send

883.04

anything greetings Sam so now we've got

886.44

very basic where we have a page we can

889.759

spit some information out to it based on

891.959

what is

893.16

sent and uh we can actually we've got a

895.759

model now that we can work with within

897.24

the page so we're going to come back

899.959

next time

901.279

around and we're going to continue

903.6

working on this we're going to get a

904.44

little more complicated uh we're going

906.16

to start adding adding some pages and

908.279

stuff like that and uh see how it looks

911.12

and sort of start building out a you

913.04

know basic navigation for app but that's

915.839

it for now we've got a we've got spring

918.16

boot we've got something going on we're

919.839

using instead of the rest controller

921.36

that we had before that we could have

922.56

used for a um for example for an API or

926.12

something like that that we have our

928.72

actual controller which is more of a web

930.839

controller and we'll just uh continue

933.56

chugging along on this actually what I'm

935.319

going to do is I'm going to actually

937

give myself a second controller real

941.12

quick uh I'm going to

945.319

do I do hello rest

949.68

controller and this guy instead let's

952.72

get rid of him let's get him back a

954.36

little

955.079

bit before we did the

957.6

Greet

961.519

there we

965.44

go so if we take

970.399

that don't need that don't save because

973.12

we don't want to break what we had we're

975.68

now going to go to the rest controller

978.279

and do it like

981.079

that we going to call him

983.6

hello rest

987

controller there we go

989.88

and so now let's make sure we got that

992.12

we got hello controller so now if we

994.319

stop and

999.04

start we have two different controllers

1001.319

floating around depending on what we do

1002.839

so greet works the

1005.519

same otherwise we get our rest

1007.68

controller so now we've got both running

1009

off the same there we go that being said

1011.88

we'll come back to it next time we're

1013.199

continue to add to our application so go

1016.04

out there and have yourself a great day

1017.48

a great week and we will talk to you

1019.959

next

1020.759

time well hello this is Rob from develop

1023.519

or building better developers and we

1025.559

have a mastermind class that will be

1027.319

starting or actually several Mastermind

1029.079

classes starting in 2024 check us out at

1031.88

technology mastermind2 24.com we've got

1035.199

all the information you need including

1036.52

some pricing early bird discounts up to

1038.839

50% off but those are things that you're

1041.24

going to have to act soon there is an

1043.559

application process so go ahead and sign

1046.12

up today thanks a lot

1049.66

[Music]