Detailed Notes
We are starting a new 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 a hello world type of web and API application using the Spring IDE.
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 going to start a new uh we getting into a new project this time around we're going to do some spring Boot and this is uh if you haven't used it it's Java based and it is a way to much like node and some of those other things that you have essentially a self-contained web server you're able to build an application and go from there uh we'll you know we'll explore it a little deeper as we go uh right now I am going to use all examples are in Springs STS um it is an eclipse based solution if you and uh I'm basically running it's it's version 4.20 there's uh if you want to you can always look out at spring tools um you can get it for either Eclipse as I've have done or uh they've got sort of you can get some of that stuff in Visual Studio code is not quite the same uh and then Theo which I have not used at all um but generally speaking depends on what your IDE is you can go from there you should be able to mostly uh get through this although it will uh things will be obviously a little different depending on your IDE particularly because I'm using this because any of the spring stuff that I have used in the past it has been very helpful for me to use what's called uh it was called Spring STS uh spring tool Suite now it's just spring tool Suite um you can find some older versions but but it's it's just a really nice environment to do spring development of any sort including spring boot so what we're going to start with is we're going to start from the scratch scratch we're going to do a project and we're going to find in here we will see that there is spring boot now we can either do getting started content or a spring starter C project I think we will probably go with we're going to start with the starter project and let's see here's our service our name is going to be because I'm going to actually use this as an app we're going to call it uh let's call it project manager actually I'm going to go with yeah I'm going to call it project manager and we've got a lot of different things we can use here you can use Gradle cotlin or Maven uh I'm going to use Maven because that's just what I like uh version jav version 8111 1721 we're going to leave it at 17 packaging I like to do the jar files and language is going to be Java uh you can use others as you've seen so my group is going to be com do uh rb- SNS because that's just who I always use artifacts snapshot uh this is going to I'll do that actually we'll do this spring boot web application we can always change this later uh package is going to be Comm rb- ss. demo I'll start with that because we'll probably add later uh I'm not going to add it to working sets if you know anything about the clips you can do that this is really just getting started uh let's see so spring boot version I can use any one of these but I'm going to use the latest production which is 3.1.5 and there's a whole bunch of stuff here I think what I'm going to do is just start with what we've got we're not going to go to deep well let's see do we want anything on the web uh actually we're going to leave it for now H wait no we do want ah we'll leave it for now we'll come back and pick those up later if we need stuff so now we should have up here we've got our little app it generated a help MD uh it generated a CMD an XML pal file which is going to be for your Maven side of it and then we've got some basic code here the application itself let's look at that before we run it and it is super simple right now so if I take whoop if I take this guy and do a run as spring boot app let's see what we get here we're going to get some stuff gets La launched and uh no active project goes to default boom it's running and really there's not much to be run with it right now so that gives us our most basic application now if we go in and do here let's just see if we look at is it tell us where it's [Music] running I don't think it's even running so let's see let's go to Local Host just because if we go to Local Host 8080 and oops it helps if I type it right and it's not running because we're not we don't have anything that we don't have actually anything really listening right now so let's uh stop that oops stop it oh I don't have a good stop here so oh it's terminated so it ran through and basically nothing happened because didn't launch anything out so what we we're going to do here is let's go ahead and make this something useful so we're going to do a new file and this is going to be just a Java and we're going whoops yep right there and Dem Mo and we're going to call it uh we're just going to call it the hello controller uh Java and so in here uh let's see we need our package which is going to be this guy and so there's our package Let's do an import uh or got spring well actually I think we can just do it easier this way let's see if we can pick them up so this is going to be a rest controller helps to actually spell stuff right public class whoops hello controller let's see if it'll actually import for me uh oh is that it ah come here no it's not going to pick that up as easily so I was hoping it was going to pick that up uh first oh let me finish this class out apologies so if I do import org spring framework web. bind annotation if I spell annotation right R controller there we go so now let's see we'll check him out in a minute so I've got a public class and then what I need to do is I'm going to do uh get mapping and this is just going to be our default and it's going to return a string let's just call this home and we're just going to do congratulations your server is running and we're probably going to need that git mapping uh which we can do the same thing except for here this is going to be get mapping so that can give us those two and then we're going to go out here and now we need to actually do something with this and so we're going to need our we're going to need a bean wh oh I got stuck in there uh we want context and you can get this stuff from the downloads if you want to get things going a little faster but we're going through it the more painful way just to sort of highlight it uh so we're going to take a bean and we're going to say uh at bean and it's going to be a command line Runner we'll call it that [Music] Runner whop public oh it's not a capital P command line Runner lowercase command line Runner and we're going to send an application context application context CTX call it that and we got our [Music] code that means we need a command line Runner here and oh we're going an application context wonder if it'll do let's see there we go that's what I was looking for so it add my command line context and then this is going to be let's do this let's say prep line location command line Runner starting up we'll just say that b name is equals x do get being oops definition names just sort them by name yeah that's right wh be names see there we go and let's do for string name be names we need that and then we need that and then we're going to do name we're just going to print the name like that get them all there there oh that one needs a semicolon there we go let's see what this does so now if I run it we got an error boom but now we get uh here we go command line Runner now he's running through now if we take our hello controller so one of the things we got to do now is we're going to turn this into web so we're come in here we're going to Spring we're going to add some starters and we're going to add the web so we're going to do spring web and that probably let's do web services too just in case and differences located oh that's fine that's fine let's see what we do [Music] here do a maven update sorry forgot to talk on that so do a maven update and now let's see what happens if we do a run at Spring boot app so we get all of our nice little stuff and uh it's listening on 8080 now so now if we go to wh don't want to go to local host.com if we go to Local Host 8080 boom congratulations your server is running so we have got a very very simple spring boot application going we have got through the uh here through the command line Runner we've got some stuff running on the command line uh to show what beans are aail available if you noticed once we added the web piece it added quite a bit more uh and we've got a basic controller so now if we go to you know our slash we can do something if we want to do something let's do real quick just to show you a quick way to do this if I want to go to slash uh goodbye then I'm going to call this goodbye and this is going to say f be that way talk to you later and if I do that and now it's going to restart I believe it restarts right there and so if I come up it's up if I do goodbye then I get a different string so we've got very very basic um spring boost you could actually use it if you wanted to you could technically use this as a you could hit it as an API um you could go you know send something to it as long as it's gets uh but this is just to get us started we will come back and talk about more next time around uh you will see a few links in the show notes basically it's just going to be the stuff to Spring you can also just you can search on it and get it fairly quickly and that will do it uh so if you have any questions send us an email at info developin or.com and we'll come back next episode and we're just going to keep you know chugging along with this a little bit so have yourself a great day a great week and we will talk to you next time well hello this is Rob from develop andur 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 Mastermind 2024 we've got all the information you need including some pricing early bird discounts up to 50% off but those or things that you're going to have to act soon there is an application process so go ahead and sign up today thanks a [Music] lot
Transcript Segments
[Music]
well hello and welcome back we are going
to start a new uh we getting into a new
project this time around we're going to
do some spring Boot and this is uh if
you haven't used it it's Java based and
it is a way to much like node and some
of those other things that you have
essentially a self-contained web server
you're able to build an application and
go from there uh we'll you know we'll
explore it a little deeper as we go uh
right
now I am going to use all examples are
in Springs
STS um it is an eclipse based solution
if
you and uh I'm basically running it's
it's version
4.20 there's uh if you want to you can
always look out at spring tools um you
can get it for either Eclipse as I've
have done or uh they've got sort of you
can get some of that stuff in Visual
Studio code is not quite the same uh and
then Theo which I have not used at all
um but generally speaking depends on
what your IDE is you can go from there
you should be able to mostly uh get
through this although it will uh things
will be obviously a little different
depending on your IDE particularly
because I'm using this because any of
the spring stuff that I have used in the
past it has been very helpful for me to
use what's called uh it was called
Spring STS uh spring tool Suite now it's
just spring tool Suite um you can find
some older versions but but it's it's
just a really nice environment to do
spring development of any sort including
spring boot so what we're going to start
with is we're going to start from the
scratch scratch we're going to do a
project and we're going to find in here
we will see that there is spring
boot now we can either do getting
started content or a spring starter C
project I think we will probably go
with we're going to start with the
starter
project
and let's see here's our service our
name is going to be because I'm going to
actually use this as an app we're going
to call it uh let's call it
project
manager actually I'm going to go
with yeah I'm going to call it project
manager and we've got a lot of different
things we can use here you can use
Gradle cotlin or Maven uh I'm going to
use Maven because that's just what I
like uh version jav version 8111 1721
we're going to leave it at 17 packaging
I like to do the jar files and language
is going to be Java uh you can use
others as you've seen so my group is
going to be com do uh rb- SNS because
that's just who I always use artifacts
snapshot uh this is going to I'll do
that actually we'll do this spring
boot web application we can always
change this later uh package is going to
be Comm rb- ss. demo I'll start with
that because we'll probably add later uh
I'm not going to add it to working sets
if you know anything about the clips you
can do that this is really just getting
started uh let's see so spring boot
version I can use any one of these but
I'm going to use the latest production
which is
3.1.5 and there's a whole bunch of stuff
here I think what I'm going to do is
just start with what we've got we're not
going to go to deep well let's see do we
want anything on the
web uh actually we're going to leave it
for now H wait no we do want ah we'll
leave it for now we'll come back and
pick those up later if we need
stuff so now we should have up here
we've got our little app it generated a
help
MD uh it generated a CMD an XML pal file
which is going to be for your Maven side
of it and then we've got some basic code
here the application itself let's look
at that before we run it and it is super
simple right now so if I take whoop if I
take this guy and do a run
as spring boot app let's see what we get
here we're going to get some stuff gets
La launched and uh no active project
goes to default boom it's
running and really there's not much to
be run with it right now
so that gives us our most basic
application now if we go in and do
here let's just see if we look at is it
tell us where it's
[Music]
running I don't think it's even running
so let's see let's go to Local
Host just
because
if we go to Local
Host
8080 and oops it helps if I type it
right and it's not running because we're
not we don't have anything that we don't
have actually anything really listening
right now
so let's uh stop that oops stop
it
oh I don't have a good stop here so oh
it's terminated so it ran through and
basically nothing happened because
didn't launch anything out so what we
we're going to do here is let's go ahead
and make this something
useful so we're going to do a new
file and this is going to be just a Java
and we're going whoops yep right there
and Dem Mo and we're going to call it uh
we're just going to call it the hello
controller uh
Java and so in here uh let's see we need
our package which is going to be this
guy and so there's our package Let's do
an
import uh or got spring well actually I
think we can just do it easier this way
let's see if we can pick them up so this
is going to be a rest
controller helps to actually spell stuff
right public
class
whoops hello
controller let's see if it'll actually
import for
me
uh oh is that
it ah come
here no it's not going to pick that up
as easily
so I was hoping it was going to pick
that up uh first oh let me finish this
class out apologies so if I do import
org spring
framework web.
bind
annotation if I spell annotation
right R
controller there we go so
now let's see we'll check him out in a
minute
so I've got a public class and then what
I need to do is I'm going to do uh get
mapping and this is just going to be our
default and it's going to return a
string let's just call this
home
and we're just going to do
congratulations your server is
running and we're probably going to
need that git
mapping uh which we can do the same
thing except for here this is going to
be
get
mapping so that can give us those
two and then we're going to go out
here and
now we need to actually do something
with
this and so we're going to need our
we're going to need a bean wh oh I got
stuck in
there
uh we want
context and you can get this stuff from
the downloads if you want to get things
going a little faster but we're going
through it the more painful way just to
sort of highlight it uh so we're going
to take a
bean and we're going to say uh at
bean and it's going to be a command line
Runner we'll call it
that
[Music]
Runner
whop
public oh it's not a capital P command
line Runner lowercase command line
Runner and we're going to send an
application context
application context CTX call it
that and we got our
[Music]
code that means we need a command line
Runner
here and oh we're going an application
context wonder if it'll do let's see
there we go that's what I was looking
for so it add my command line context
and
then this is going to be let's do this
let's
say prep
line
location command line Runner
starting up we'll just say
that b name is
equals x
do get being
oops definition
names
just sort them by
name yeah that's
right wh be
names see there we go
and let's do
for
string
name be
names we need that and then we need that
and then we're going to
do name we're just going to print the
name like
that get them all there
there
oh that one needs a semicolon there we
go let's see what this does so now if I
run
it we got an error boom but now we
get uh here we go command line Runner
now he's running through now if we take
our hello controller so one of the
things we got to do now is we're going
to turn this into web
so we're come in here we're going to
Spring we're going to add some starters
and we're going to add the
web so we're going to do spring
web and that probably let's do web
services too just in
case
and differences
located
oh that's
fine that's fine let's see what we do
[Music]
here
do a maven update sorry forgot to talk
on that so do a maven
update and now let's see what happens if
we do a run at Spring boot
app so we get all of our nice little
stuff
and uh it's listening on 8080
now so now if we go to wh don't want to
go to local host.com if we go to Local
Host
8080 boom congratulations your server is
running so we have got a very very
simple spring boot application going we
have got through the uh here through the
command line Runner we've got some stuff
running on the command line uh to show
what beans are aail available if you
noticed once we added the web piece it
added quite a bit more uh and we've got
a basic controller so now if we go to
you know our slash we can do something
if we want to do something let's do real
quick just to show you a quick way to do
this if I want to go to
slash uh
goodbye then I'm going to call this
goodbye and this is going to
say f be that
way talk to you
later and if I do
that and now it's going to
restart I believe it restarts right
there and so if I come up it's up if I
do
goodbye then I get a different string so
we've got very very basic um spring
boost you could actually use it if you
wanted to you could technically use this
as a you could hit it as an API um you
could go you know send something to it
as long as it's gets uh but this is just
to get us started we will come back and
talk about more next time around uh you
will see a few links in the show notes
basically it's just going to be the
stuff to Spring you can also just you
can search on it and get it fairly
quickly and that will do it uh so if you
have any questions send us an email at
info developin or.com
and we'll come back next episode and
we're just going to keep you know
chugging along with this a little bit so
have yourself a great day a great week
and we will talk to you next time well
hello this is Rob from develop andur
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 Mastermind
2024 we've got all the information you
need including some pricing early bird
discounts up to 50% off but those or
things that you're going to have to act
soon there is an application process so
go ahead and sign up today thanks a
[Music]
lot