📺 Develpreneur YouTube Episode

Video + transcript

Spring Boot Simple App

2023-11-16 •Youtube

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
1.35

[Music]

27.32

well hello and welcome back we are going

30.359

to start a new uh we getting into a new

32.279

project this time around we're going to

33.68

do some spring Boot and this is uh if

36.92

you haven't used it it's Java based and

39.719

it is a way to much like node and some

42.28

of those other things that you have

43.44

essentially a self-contained web server

45.96

you're able to build an application and

47.64

go from there uh we'll you know we'll

50.079

explore it a little deeper as we go uh

52.359

right

53.239

now I am going to use all examples are

56.199

in Springs

58.12

STS um it is an eclipse based solution

62.8

if

64.84

you and uh I'm basically running it's

67.84

it's version

69.84

4.20 there's uh if you want to you can

73.759

always look out at spring tools um you

77.2

can get it for either Eclipse as I've

80.52

have done or uh they've got sort of you

84.04

can get some of that stuff in Visual

85.479

Studio code is not quite the same uh and

87.88

then Theo which I have not used at all

91.04

um but generally speaking depends on

92.84

what your IDE is you can go from there

95

you should be able to mostly uh get

97.04

through this although it will uh things

99.64

will be obviously a little different

100.92

depending on your IDE particularly

102.64

because I'm using this because any of

105.439

the spring stuff that I have used in the

107.759

past it has been very helpful for me to

110.36

use what's called uh it was called

112.96

Spring STS uh spring tool Suite now it's

116.32

just spring tool Suite um you can find

118.92

some older versions but but it's it's

120.56

just a really nice environment to do

122.6

spring development of any sort including

125.759

spring boot so what we're going to start

127.479

with is we're going to start from the

128.72

scratch scratch we're going to do a

130.599

project and we're going to find in here

133.36

we will see that there is spring

135.239

boot now we can either do getting

137.319

started content or a spring starter C

140.56

project I think we will probably go

145

with we're going to start with the

146.959

starter

148.76

project

150.72

and let's see here's our service our

152.599

name is going to be because I'm going to

154.8

actually use this as an app we're going

157.2

to call it uh let's call it

162.959

project

164.959

manager actually I'm going to go

167.56

with yeah I'm going to call it project

171.56

manager and we've got a lot of different

173.8

things we can use here you can use

175.68

Gradle cotlin or Maven uh I'm going to

178.68

use Maven because that's just what I

180.64

like uh version jav version 8111 1721

183.519

we're going to leave it at 17 packaging

185.519

I like to do the jar files and language

188.28

is going to be Java uh you can use

190.76

others as you've seen so my group is

193.08

going to be com do uh rb- SNS because

197.72

that's just who I always use artifacts

200.959

snapshot uh this is going to I'll do

204.879

that actually we'll do this spring

207.519

boot web application we can always

209.84

change this later uh package is going to

213.959

be Comm rb- ss. demo I'll start with

218.599

that because we'll probably add later uh

220.4

I'm not going to add it to working sets

221.68

if you know anything about the clips you

223.2

can do that this is really just getting

225.4

started uh let's see so spring boot

227.92

version I can use any one of these but

231

I'm going to use the latest production

233.239

which is

234.879

3.1.5 and there's a whole bunch of stuff

238.68

here I think what I'm going to do is

241.439

just start with what we've got we're not

244.48

going to go to deep well let's see do we

246.12

want anything on the

249.079

web uh actually we're going to leave it

251.12

for now H wait no we do want ah we'll

253.959

leave it for now we'll come back and

255

pick those up later if we need

256.72

stuff so now we should have up here

261

we've got our little app it generated a

263.4

help

264.6

MD uh it generated a CMD an XML pal file

269.24

which is going to be for your Maven side

271.16

of it and then we've got some basic code

274.08

here the application itself let's look

276.36

at that before we run it and it is super

279.96

simple right now so if I take whoop if I

282.08

take this guy and do a run

286.52

as spring boot app let's see what we get

290.199

here we're going to get some stuff gets

291.96

La launched and uh no active project

295.56

goes to default boom it's

298.16

running and really there's not much to

301.36

be run with it right now

304.24

so that gives us our most basic

309.199

application now if we go in and do

314.96

here let's just see if we look at is it

318.759

tell us where it's

319.44

[Music]

320.96

running I don't think it's even running

322.8

so let's see let's go to Local

326.24

Host just

328.479

because

330.56

if we go to Local

334.8

Host

337.8

8080 and oops it helps if I type it

345.56

right and it's not running because we're

347.88

not we don't have anything that we don't

349.199

have actually anything really listening

351.039

right now

352.16

so let's uh stop that oops stop

358.479

it

366.44

oh I don't have a good stop here so oh

369.88

it's terminated so it ran through and

372.36

basically nothing happened because

374

didn't launch anything out so what we

376.199

we're going to do here is let's go ahead

378.039

and make this something

380.479

useful so we're going to do a new

383.24

file and this is going to be just a Java

386.84

and we're going whoops yep right there

389.12

and Dem Mo and we're going to call it uh

392

we're just going to call it the hello

395.599

controller uh

399.28

Java and so in here uh let's see we need

402.8

our package which is going to be this

411.68

guy and so there's our package Let's do

415.08

an

418.039

import uh or got spring well actually I

421.599

think we can just do it easier this way

423

let's see if we can pick them up so this

425.479

is going to be a rest

435.319

controller helps to actually spell stuff

438.52

right public

440.8

class

442.4

whoops hello

444.68

controller let's see if it'll actually

446.599

import for

448.319

me

454.68

uh oh is that

458.199

it ah come

464.68

here no it's not going to pick that up

467.039

as easily

468.639

so I was hoping it was going to pick

470.72

that up uh first oh let me finish this

473.159

class out apologies so if I do import

478.319

org spring

484.159

framework web.

489.44

bind

491.159

annotation if I spell annotation

494.96

right R

498.479

controller there we go so

506.4

now let's see we'll check him out in a

508.479

minute

509.96

so I've got a public class and then what

511.96

I need to do is I'm going to do uh get

515.56

mapping and this is just going to be our

522.56

default and it's going to return a

531.72

string let's just call this

538.2

home

544.519

and we're just going to do

547.2

congratulations your server is

553.959

running and we're probably going to

558.36

need that git

561.68

mapping uh which we can do the same

565.2

thing except for here this is going to

568.12

be

570.32

get

572.92

mapping so that can give us those

575.8

two and then we're going to go out

579.6

here and

583.2

now we need to actually do something

585.72

with

589.399

this and so we're going to need our

592.519

we're going to need a bean wh oh I got

595.32

stuck in

598.12

there

603.079

uh we want

607.32

context and you can get this stuff from

609.68

the downloads if you want to get things

611.279

going a little faster but we're going

612.76

through it the more painful way just to

615.12

sort of highlight it uh so we're going

617.24

to take a

620.32

bean and we're going to say uh at

627.839

bean and it's going to be a command line

630.48

Runner we'll call it

632.399

that

633.65

[Music]

635.44

Runner

639.88

whop

641.6

public oh it's not a capital P command

645.079

line Runner lowercase command line

650.56

Runner and we're going to send an

652.36

application context

655.88

application context CTX call it

660.44

that and we got our

662.23

[Music]

666.399

code that means we need a command line

669.48

Runner

676.2

here and oh we're going an application

682.92

context wonder if it'll do let's see

685.959

there we go that's what I was looking

687.959

for so it add my command line context

691.36

and

698.36

then this is going to be let's do this

701.48

let's

704.56

say prep

716.36

line

717.959

location command line Runner

721.279

starting up we'll just say

732.639

that b name is

736.92

equals x

739.32

do get being

745.44

oops definition

747.88

names

754.44

just sort them by

757.56

name yeah that's

760.56

right wh be

773.36

names see there we go

777.32

and let's do

779.399

for

780.959

string

783.519

name be

790.68

names we need that and then we need that

794.44

and then we're going to

797.199

do name we're just going to print the

799.48

name like

803.36

that get them all there

807.76

there

810.079

oh that one needs a semicolon there we

818.639

go let's see what this does so now if I

821.839

run

830.16

it we got an error boom but now we

835.6

get uh here we go command line Runner

840.519

now he's running through now if we take

842.079

our hello controller so one of the

844.36

things we got to do now is we're going

845.48

to turn this into web

847.12

so we're come in here we're going to

849.24

Spring we're going to add some starters

851.399

and we're going to add the

855

web so we're going to do spring

858.04

web and that probably let's do web

861.36

services too just in

867.68

case

869.36

and differences

872.079

located

877.16

oh that's

885.959

fine that's fine let's see what we do

889.11

[Music]

897.68

here

907.72

do a maven update sorry forgot to talk

910.32

on that so do a maven

912.68

update and now let's see what happens if

916.48

we do a run at Spring boot

922.199

app so we get all of our nice little

924.72

stuff

927.6

and uh it's listening on 8080

931.8

now so now if we go to wh don't want to

935.079

go to local host.com if we go to Local

937.519

Host

939.88

8080 boom congratulations your server is

943.12

running so we have got a very very

947.56

simple spring boot application going we

950.44

have got through the uh here through the

953.319

command line Runner we've got some stuff

954.92

running on the command line uh to show

957.36

what beans are aail available if you

959.36

noticed once we added the web piece it

962.04

added quite a bit more uh and we've got

964.639

a basic controller so now if we go to

966.6

you know our slash we can do something

968.24

if we want to do something let's do real

970.399

quick just to show you a quick way to do

972.92

this if I want to go to

974.639

slash uh

978.24

goodbye then I'm going to call this

984.319

goodbye and this is going to

987.199

say f be that

992.199

way talk to you

994.68

later and if I do

999.44

that and now it's going to

1001.759

restart I believe it restarts right

1004.959

there and so if I come up it's up if I

1007.6

do

1011.12

goodbye then I get a different string so

1014.36

we've got very very basic um spring

1018.24

boost you could actually use it if you

1019.639

wanted to you could technically use this

1022.16

as a you could hit it as an API um you

1025.28

could go you know send something to it

1027.959

as long as it's gets uh but this is just

1030.48

to get us started we will come back and

1032.24

talk about more next time around uh you

1034.6

will see a few links in the show notes

1036.959

basically it's just going to be the

1038.079

stuff to Spring you can also just you

1040.12

can search on it and get it fairly

1041.64

quickly and that will do it uh so if you

1045.319

have any questions send us an email at

1046.679

info developin or.com

1048.919

and we'll come back next episode and

1051.039

we're just going to keep you know

1052.32

chugging along with this a little bit so

1054.84

have yourself a great day a great week

1057.039

and we will talk to you next time well

1059.88

hello this is Rob from develop andur

1061.679

building better developers and we have a

1064

mastermind class that will be starting

1065.6

or actually several Mastermind classes

1067.44

starting in 2024 check us out at

1069.84

technology Mastermind

1071.799

2024 we've got all the information you

1073.88

need including some pricing early bird

1076.08

discounts up to 50% off but those or

1078.76

things that you're going to have to act

1080.28

soon there is an application process so

1083.28

go ahead and sign up today thanks a

1087.63

[Music]

1101.4

lot