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
[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]