How to Create a Spring Boot Web Application

Hello and welcome to the video tutorial:
How to create a spring boot web application in this video tutorial you will learn how to develop a Spring Boot web application with Spring MVC and JSP or ThymeLeaf I am Nam Ha Minh from throughout this video tutorial I will guide you how to develop sample project with Java 8 (JDK 8) Eclipse IDE with Maven If you ever developed spring MVC application before you know that you have to write pretty much boiler-plate code just for the configuration which you can use the same for all most projects this repeated and
a boring tax consumed short term which should be spent on developing a business
logic for the application and now with spring boot and things to get a lot
easier you know with spring put all the configurations automatically done for
you Auto configuration which sensible force
so you can quickly zoom on in the coding visited logic which are worrying about
the configuration details to create a spring foot project go to the spring
initialized web tool at start touch spring at i/o you see the default options mavin brozac
Java and spring put version 2.0 point four and the information for music
metadata s group is an echo Java artifact is spring boot web and in the
dividend C’s type web to develop a full stack web application you can click here
to see more options for example butt-kissing type Java version here I
changed the back back his name to only natkho Java their description of swing
boot web application then click generate project now if we download a zip file
and I save it in a folder on my computer spring same here and so in folder and 8-track just as if
I retract here okay so we have a cigarette project
Springwood web app now let’s import this this project in Eclipse IDE we see my
Eclipse IDE I’m using eclipse oxygen version 2 when you find import
and click general rice projects from photo archive next and here choose a
directory which you have extracted on my computer I have extracted two spring and
spring book map ok and you can see Eclipse detects the boesak as maven and
click finish wait for a moment why it is updating a
maven project configuration you can click on the status bar to see the
progress you see it is and allowing various dependencies for the project if
she Spring Framework so just witty okay
finish you see the generated prozac we imported here spring good web this is as
a teacher structure of the project you can see various lot of Java files
dependencies for spring boot and the web starter if she took an embed spring web
MVC there you need many many many jar files let’s open the maven project by
the bomb dot XML file here view is I sent no code you see our project a
package in time is a jar and if she there are two divided season here the
first one is spring boots data web which enables web development which being a VC
and embedded tomcat server and the second even see is for tests in this
tutorial we don’t need to use test so you can delete this a dependency safe you can see yes
error here in the test class so the latest class at one okay and you can see
in the package net not Kodava there’s a class
Springwood web app application not survive she this is an entry point class
to run our spring boot web application if she the annotation spring boot
application is used this annotation does magic work to start the embedded took a
server configure spring dispatches of it and so on to make a application up and
running and you don’t have to write any configuration for spring MVC and this is
a static folder and the NRC / min / the resources you put those static Christ
here for example HTML files and this is a timeless directory where you put the
template files for example time-leap template rice and this is application
properties file you can specify original configuration for the project here for
example to configure low-wing spring every severe is over silver bought
number and so on so this is a basic easy in each instruction of the brozac
generated by the web tools bring initialize right now we can start our
spring program application all right click here run as java application and
you’ll see the spring below appears and this is a logging information you see let’s go get started on port 8080
with the context path empty and started spinning booger application now we can
use the internal web browser to try to assess our website window so view as a
type internal then it’s like internal web browser
I move the internals of you here so we can see better okay so we have to
type the urs HTTP : level 4 slices low cost the bottom is
8080 and because the context part is empty so we don’t have to try anything
after the phone number hit enter you’ll see we want an arrow here the web page
cannot be found because we haven’t created any welcome fine
yet for the application but you can see the lovely message it is initializing
using spring frameworks of it now I tried to see in Chrome browser you see
it is place Arabic for 0 for arrow stay just now let’s create a welcome passion
for the application you know spring boot looks for the welcome path based in
static folder here with the name index dot HTML so let’s create a new HTML of
line here HTML next in the index.html finish change the page
title to my contacts spring good web application example then we have the
heading 1 in the Welcome page my contacts and create a hyperlink here click here to this level contacts the
relative URL is list underscore contact force last least underscore contact so
this is d4 welcome paste put it under static folder
here and now stop and start the application again because a Springwood
application is actually a standalone java application so you have to stop the
currently learning one first and run it again now you can click here or spring
Google application okay it started and you can note this love wing by adding welcome past past
past results static sass index dot HTML now let’s refresh the web browser you
can see this is a content of the index ETFs which we have created my contacts
and click on this hyperlink you see an error because we haven’t invented any
handler for last URL that child to see in chrome click here and she so there’s
a different differences when the error appears mock between internal web
browser and chrome Allah this is before welcome press as a static based if you
want to have a dynamic or compassion for example this be on tablet template if
you have a tablet amplifier you put under the template folder here and you
want to have a dynamic well compassion in as SP you can create a controller
class with a handler method for example or last create a new into
class here class for example controller finish this year’s spring controller
class so and notated it with the SI controller annotation and Rio Hanlon
Italia for example string no cam and specify the request mapping notation or
this method specify the URL button is a forward slash so this method is
responsible to handle requests to the website and contacts route which is a
home page you can return a view name for example index now let’s build something
in this method controller welcome certify we see a very
simple spring MVC controller with the handler method welcome that is invoked
when the visitor and the users assess the replication now I stop and start application again now you can see you love being here
see I you see mapped for was last onto public up controller that we all
committed this that means the Welcome method is mapped to handle requests to
this URL now refresh our internal web browser you see we still have error but
he develop when you can see this message that means the hello method is invoked try to see in chrome we got 0 for 0 for
error okay be worthy of the for 0 for error because a swing MVC could not file
the view with the name index and we saw you or to remain recipe view to exist in
the next few minutes our web application we display a list of contacts so let’s
create a domain model class to represent a contact
stop I click new class the customer is contact finish and it has three fuse name email and country zette weather
settles and constructor so it contractor using fuse okay so z culture changing
fields their data setters so go for the three fuse country you have a name click
ok and now we have a very simple domain model class the contact class the next
best create a business class that provides a method to return list of
contacts object so create a new class contact business finish we have a method that returns wrist up
contact objects contacting their contact list sorry this should be server not UT
not list list contact list contact equal new released released filter list
contact we returned the hard-coded list in your life you may need to connect to
database to let the contacts list here we simply create a hard-coded these are
contact objects please contact add a new 11 new contact name is name email so
country we had the for example where for contacts the first one is Mary Jean email with
John and Jimmy calm countries USA the second contact name is Tom Smith Tom
sweet I look calm England the third contact is
Jean posture Jean one two three no kanji is an example
Australia and I’ve fought contact least civil Chris here is Shiva Krishna G no
calm country is India okay that’s very simple and use in the index
well compass you can see we have a high plane click here to list all contacts
with the relative URLs for was vastly standard score contact and we create a
handler method in the controller class to handle requests coming from this hi
bling let’s change request mapping your voice is better to test test now create
a new hello method works in form list contact request my pain request I was last least underscore contact
which II the you are button in the welcome pass you see he should match and
in this hand a little bit on the view name contact now last reach if the contact list from
contact busyness create a new contact vicious vision is equal new business net
contact list then sized amendment in local variable we need to put this list
to the model so specify now woman model here an attribute attribute name is
contacts and really with list contact okay this is a handler method in the
controller asked very simple right now let’s see how to use JSP with spring
put to use SP enable the SB we need to add another div and c in the palm of XML
hi Ropin bombastic ml5 flip p-value see and we need to add a devalue see the group
IDs OS z dot a patch not to get not embed artifact ID is term cat – and bad
– last but jasper is a thespian gene for a tomcat EDD it is required to enable
the SP compliation and execution wish to bring good web application we don’t have
to type us in because the spring boot managed the version automatically then
click OK mushi save this file and movin
automatically updated as our flies here open and you can see Tomcat and bears as
per appears near by default a spring boot looks for the SP pcs in web app
directory and the the as Isis last main and treachery so you create a new directory here and as I
see men new folder the folder name is a web app you see and without any view
resolver specified we should return the actual JSP file name in the handler
method for example in this test method ok we turn tests lost the SP and this
test this does SB a is expected to be in the web app directory here
so last critters SP if I hear as a zest be next test not less be finish change a
page title to sample SP this heading 1 please see this be page and you can
write some this here code here to test is dynamic execution for example I print
the current date and time here new Java not UT not yet ok step up controller
class as well now last run the application and assess our web
application from the URL test you see test here and NFC you see as SP
fish and current date and time now let’s test it in the Chrome browser task you see the time in chrome is
different than the time in the internal web browser
that means the SPS is really a dynamic so that’s basically we put the SP files
here under the web app victory and the Odyssey main and to follow the common
convention and to protect ours sv basis and we should create a directory called
web – INF here new folder for F and F and the files and the web-inf is as
protected by the web server and create a new folder to put all these SP files
here you can career as a folders to put images CSS
and JavaScript files now let’s configure Springer with you we reserved open the
application output device here you can add a new property name is print on
every see not revealed or graphics the graphics is false last web 9f this
before was last and add another property for surface spring northern BC not
revealed or surface value is not the SP finished see the southerner see we have
specified two properties to confuse a spring every see a view resort now in
the hello method of the controller class you just return the name of the view here we just returned name test and now
we should move the test less P Phi e to web-inf and SP here okay now let’s now
run the application again nearest you see it is still walking go
back to the homepage you see click here we got error because because we haven’t
invented the animated forest contact yet so now last sorry
we already implemented the hello method for the email list the SKA contact here
but we haven’t created the SP pest the view contact if you run east in a Chrome
browser you will see a squirrel an unexpected error this view could not be
found so let’s create an assist as SV pet I click here new as SP file name is
contact not the SP finished and change page title to contact list spring boot
your web application example we have a heading one tag here my
contact list we use a table the first table row is a heading row name email
and country save the file stop the application and study the VIN real fast and you’ll see it applies my
contact list name in your country now to display the list of contact objects in
the model you see we have contact list object in the model and to display the
list no contact object we need to use you can use the STL so to use the STL
you we need to add the dependency for the STR in the Palmer
XML file so here click Add to add dependency for the sto the group ID is
Java X dot servlet artifact is the SDL we don’t have to
type as an ass in a springboard man is is the version ok click Save and you
wish you can see this tell Java appears here now
tax under JSP page we use sto contacts with specified target objective
directive here to use the SDL contact tap lip uie HTTP server Nelson calm just
be last year calm perfect prophesy see ok and now we use the a our for each
stack here from see for each items is collection with G which is a name of the
variable of the attribute name here contact and variable name for each
object is contact now for it item in the collection we create a new
table row the first column is the contact name con type not name then
email in country email country we need to specify border for the table witness
nobody was about 10 pixel and have a climate change the heading and the table
and sent as a headache align center okay okay so far so good now let’s stop the
application and studied again in the local gracias you can see the URL for
last is mapped to the test method in the upcountry class and for at least contact
you air pattern is mapped to the list contact method
now let’s refresh the browser and you see the table rest display nicely you
see now let’s see Chrome browser you see my contact list but I would write next let’s see how to
use time leaf with swing put to use a tablet as the viewer technology instead
of as SB we need to add spring boot starter dependency of our term leaf and remove the dependency tomcat and just do
so select this tool even C and click remove and we add the dependency for
swing boot stuttered time leave buddies or Z dot the swing framework not boot
and artifact ID is spring – would – stutter – time lip term live week okay and she in the XML code we had the
dibiase for spring first at a time live here save the file stop the application and if she timely
suffice appears here Springwood looks for some bleep template
files in a tempest folder here so we create a new HTML template for time leaf
here HTML next name in s contact dot HTML finish you can copy some code in
the context endows SP which I will copy the title here and in the HTML here we
need to specify the nips play for Tom leaf pistol
and as Nick watt TDP the first one is an Aussie it xhtml and the second is for
Tom leaf I was if okay when copies is good remove forge for it
is for the stair and we use term lip which is different here for time lift we
specify the sorry we specify the attribute contact in contact list and forest table cell we specify the text is
in techies contact dot name no okay copy for
country email country email country okay we need also to Center the table okay
that’s it as you see the time leaf template you see we just change the view
and the controller remains intact we don’t have to change your model just
change the view and now the last start application and test you can add a like
here to verify it is actually from Tom Leaf tablet now run the application refresh we have error here contact not
name sorry my mistake now restart the application this contact we first you see my contact
list Tam leaf last test of a Nina Chrome browser you see so last time leaf tablet
cooks with string put logging is done very well with supreme put you see blowing we message in case you want to
change the lock level for all the lock my C C’s in the application you can
specify a property in the application dot properties file with a Halloween not
level not route equal level a lock level so just we applied to
all the lovers was a lock Messi’s for example you can see by default Alok
level in spring book II info stop the application now we change the level to
one display only the lock message for warning and error now let’s start the
application and you see our springboard application has been started but if she
no loving message appear here because the local level has changed to one that
means is so local my sis only for warning and error message now
last I said our web application here look here you see there’s no lovely mess
it up here here you can also change the look level for specific
server package for example Lachlan not level and the package name for example
became netcode lava level is in for this specifies that in so low a message from
the practice net but core Java from the level info and above it for error one
now let’s run the application again you see there are two there are some local
machine I for the back east natkho Java you see automatically
certain by spring boot la loi if she and as I love my sis form spring framework
and as a low cost no soul for part number of embedded – cassava is
a DAT and you can override this before what number by specifying a property in
the application that property is fine here you see our web application is
running on one 8080 now let’s change bot number of the server we should be five
will put the server dot but for example we change the part to 80 and start the
application of n now let us in a Chrome browser refresh and I’ll see an error
message this side can be rich because the part number has changed and let
delete the part about it t at easy for port for HTTP so we don’t have to
specify in the UL so just refreshed finish a pot number has changed and you
can see the default context path is empty so you can assess the application
via localhost and then the URL you want to change the default context part you
can specify a property in the application and a properties right here
server dot servlet not context – but equal to context pad for example we submissive I
the context buddies contact app here safe and now I stop and start the
application again okay now let let’s try to refresh this best and we wat LMS is
because a contact spot hair change now we need to enter the contacts parties
contact up you see we had to assess our application with new context but click
here we want error message because the URL is a great tip to the server’s root
so we need to change the Ling here in the index.html sorry you need to remove
the forces here now stop and start the application event low cost contact app
click here Oh still the same don’t worry you can specify this contact
here missed contact and it works you see now remove the context part here and
remove the configures or what number and we will you agent Halloween okay I’ll
stop the application you know major advantage of spring boot is that it
practice the web application and embedded to cross over into a single
executable jar file that’s a very convenient for programmers if you used
time leaf you can use both you can use as a package entire East Israel WA but
for this week you had to use the Machine time whoa now let’s see how to practice
our epic web application to verify for time with me establish we need to run them a van Gogh
right-click on the project in run s maven bill and specifies a low is
packaged click run we got an error message
Beulah here because we need to use as idk instead of the is no problem so
right-click here on a window preferences Java installed a ie and here you can
specify a head standardly I’m next and here you can select directory object
identity we work Java JDK warning poet finish checkers idk a blind close in our
last Runza maven go away click here you see it need needs two dollar summer
as our Feist you see you success and you can see Jeff is acquitted here in the
tacit directory you see this is a project directory and under here go to
the target directory and there’s Jeff I created here this is a executables fi
for our web application now let’s run this application open a command line
prompt and change the directory to this directory and specifies
common java – Cheyenne job my name is ring boot and energy swing below will
appears application starting you see Tom get started on board 8080 and she’s a
mapping for test for list underscore Kentucky now let’s test our application
in Chrome now we had to a celebration by a pot 8080 and click here to listen or
contacts you see it works very well with executables are fine however the SP
doesn’t work with Jacques in type also you see it works in Eclipse but actually
it doesn’t work let last use the SP now to cut as aspirins STL and the packages
int is the jar you see save the file no Cayenne stop the application with Tom
beef chained to the parent directory and if you you use commander you can tie MV
and clean to clean the project and every end
kiss to package the project you see your success and now let’s run this new
executable Java change Ector e to touch it and ties have a spring the
application has been started in our last test in Chrome browser click here you
see we got an error message ty 4 0 4 the view could not be found
that means the SP doesn’t work with the abacus in time so you had to change the
package in tiny livin to war here change back
– whoa – generate a wolf I instead of – ah yes stop the application now clean
the prozac and practice again – a wolf hi you see now we have a wolf eye you
see a wolf I instead of a sci-fi because we have changed the packaging tied to
work now last this year an executable wolf eyes now last we can run this
executive wolf I okay the application has been started now last test in chrome
Raja you see it works now for the SP with an executable jar file so to
remember with Tom leaf you can use either
yeah or were packaged packaging but for the SP you had to use work packaging to
package the application and this was how to develop a spring MVC web application
which swing boot in Eclipse IDE SH you have learned how to use the SP and Tom
leaf and remember how to practice the application with
this be entirely this be is working with war magazine only and timely work with
either was a pact is a quick easy thank you for watching and see you in the next
video I’m not coming from coach Nevada net

16 thoughts on “How to Create a Spring Boot Web Application

  1. I love watching and learning from your videos Nam.
    Please make regular videos any complete project or application
    Thank you.

  2. Hi Nam.. At 1:02:20 you clicked on contacts list link. it didn't work coz the href didn't include the new context path. Do we need to include the context path in all the places where we mention hrefs. Is there a way to make this work even without including the context path explicitly. I would like to keep the context path configurable so that if I change it, I don't have to make that change all across the
    htmls. Please suggest.

  3. 1:43 Create SpringBoot Project
    13:46 Create Welcome Page
    18:31 Create Spring Controller Class
    22:48 Create Domain Model Class
    24:24 Create Business Class
    31:06 Use JSP with SpringBoot
    47:52 Use ThymeLeaf with SpringBoot
    55:15 Configure Logging
    58:47 Configure Tomcat Server
    1:03:17 Package to Jar (ThymeLeaf)
    1:07:59 Problems with JAR packaging (JSP)
    1:09:52 Package to WAR (JSP)

    Thanks for the video it is very helpful with learning some of the technologies that work with SpringBoot!

  4. It's very frustrating trying to follow up with your video. Your voice is very very low and you don't bother to zoom the screen so that viewers can see what you are typing. You should always consider that your are teaching people around the world not yourself.

  5. use tomcat-embed-jasper , in WEB-INF, in my file .jsp i cant import files .js , any solution? or never i can import one file .js in this folder(WEB-INF)?

  6. Hi, when I try localhost:8080 I get "Internal Server Error" but when I try localhost:8080/index.html works fine. Do you know what is going on? Could it be a problem with local javax.servlet jar?

Leave a Reply

Your email address will not be published. Required fields are marked *