#5 What is Spring Boot?

πŸš€ Add to Chrome – It’s Free - YouTube Summarizer

Category: N/A

Building WordCloud ...

Summary

No summary available.

Transcript

00:00

welcome back aliens my name is a ready and in this video we'll talk about spring boot so before we talk about spring boot the target for this video is 250 comments now till this point we have talked about spring framework right and we are excited to understand how this framework works and whatever things it

00:16

promises how it deals with that so yes spring framework is amazing right and whatever application we are going to build now is with the help of spring so let's say you want to build an application this can be anything in the world even it can be a huge application

00:32

or it can be a application for hello world typically what happens is when you want to build the application of course you have your Java code with you and then to make it work spring says hey you know doesn't matter how many classes you have I will take care of the object

00:47

creation and you are quite happy because now you don't have to worry about the objects spring says I will take care of it so let's say in your application you have you have three classes and you say hey Spring create object of this three classes and spring is happy to do that so let's say in your application now you

01:03

have 100 or thousand classes can spring handle all the objects of course it can but the question is do you want spring to handle all the classes you know most of the time we don't even want the object of few classes let's say you have lot of classes here and out of all these

01:20

classes you need objects of only few classes how do you talk to your spring framework by saying hey don't create objects for everything I don't want all those things I just want few spring says okay tell me which one you want and that's where when you talk to the

01:36

framework we have to do that in the configuration file it can be XML file or it can be a property file but you have to talk to the framework that means just because you're using a framework you will not be able to run your code in the first go you have to first do the

01:53

configuration next part let's say if you are building a web application now if you want to run your web application basically you need a server in terms of java uh we need something called a tomcat server of course we have multiple options let's say if you want if you're building a web application in Spring you

02:10

need to have a tomcat server that means in your machine even before you run your code you have to make sure that you have installed Tomcat you have configured Tomcat then only you can run your application so you'll be saying hey what's wrong with that I mean of course

02:25

we can do configuration we can install Tomcat see the problem is when you have a long project it makes sense to spend few hours or days doing the configuration because the project will go for a year but what if you are doing some experiment what if you want to get

02:41

started in few minutes see most of the languages nowadays they are doing that if you talk about python or JavaScript they have their Frameworks and if you want to at least print hello world you can do that in minutes now this is what spring was lagging way back and Java was

02:58

lagging way back and that's where we got something called a spring boot now spring boot says all your problems of configuration let me take care of it what if you can get your project running in few minutes and that's what spring

03:13

boot gives you it's not a new project is there from a long time but it basically solves your problem of building a project in less time so does it means that spring boot is different from Spring framework not exactly see underlying it's all spring framework

03:29

right on top of that you have one more layer of spring boot so you can actually build application directly using spring framework or if you want to make it easy you can use spring boot again that's an optional stuff but this optional thing is very very important and uh it will

03:46

make your work faster so basically we can use a spring boot which is a open unated framework which means it will give you certain things the way it wants and you can simply use it to run your application let me show you how what I'm talking about so let's say if I go to the spring.io the official website and

04:02

instead of this website if I just say start. spring.io it will take you to a website now see when you talk about building a project in different idees we have an option of directly saying a new project and you can create a spring project in spring project basically you create a mavin project again we'll see

04:19

that in in sometime or in the upcoming videos but basically you have to create a m project at the spring dependency a lot of different steps right inell idea ultimate version gives you a an option of creating a spring boot project directly but since we are not going to go for the ultimate version we don't

04:34

want to pay for it we have a good alternative what you can do is you can go to Spring Riser which is this website start. spring.io and you can mention what kind of project you are building so I'm building a MAV project this is a build tool the language I'm going for is Java and then the spring boot version so

04:50

this is update version so you can see we have 3.2.5 we can even go for the rc1 but I just want to stick to the stable one which is uh 3.2.5 and depend upon when you're watching this you can just use that particular version the group I will say com. telescope and the project

05:06

name is let's say uh demo app and then the packaging is I'm going for Java now this this is where the beauty lies you know if you talk about a spring framework or any web application in Java you can create a project and if you want to deploy it on the cloud basically you

05:21

create a v file so v v stands forb web archive and then you basically push your W file in the Tomcat to run it multiple steps right spring boot says don't worry you can create a jar file but the problem is jar file we cannot run jar file on the Tom Cat then how it would

05:38

work what if you don't need external Tom Cat what if the project itself has a tomcat I mean that will be awesome right so basically spring boot says if you want to build a web project you will get a embedded tom cat so I will select jar

05:54

and I'll show you what I'm I'm talking about and then I can select my Java version so in this machine I got Java 21 so I will go with that it is LTS version so it's safe to use and dependency so what are things we need so of course if you remember when we talked about spring framework I mentioned that there are

06:10

multiple projects inside spring and we don't need all depending upon your use case you will choose one so I will click on ADD dependencies so you can see there are lot of options here to choose from and you don't have to know everything uh use whatever you need example here I want to

06:27

build a web application so I will simply say uh spring web if you want to add database connectivity you can also add uh jpa but we don't need that at this point uh if you want to get a longbox support you can choose that if you want to uh use graphql you can use that uh so

06:44

as I mentioned there are so many options here but I just want to stick to one which is bring web and click on generate now before I click on generate I will show you how this configuration looks like so it will give you the entire configuration we can see we got a dependency which is spring boot stter web here the Java version is 21 this is

07:02

my project name and this is the spring boot version which we are using and behind this it will use spring framework I will show you the code so click on download you can even click on the uh generate here so you can see in the downloads I got this project which is demo app what I will do is I will just

07:18

unzip it so unzipping is done on the other screen but uh I will just open that project now in my ID now you can use any ID here you can use Eclipse you can use vs code you can use intellig idea Community version version or theate version so I'm using a community version here just to show you the proof I will

07:34

click on not update I will click on about and you can see this is a community version and I will click on open the project so this is the project which I've downloaded click on open and voila you got your project and the beauty is if I expand the dependencies I

07:51

think it will take some time to download okay download it too fast and you can see it added so many dependencies here uh the for the Jackson for Json conversion uh we got uh micrometer for observing we got Tomcat you can see we got embed Tomcat so basically you don't

08:08

need to have the external Tom Cat here and if you go down uh we got spring boot but also we got spring framework you can see we got spring code so all the things which are spring required for spring code or spring project we got it here okay uh let me just drop it here and now

08:23

let me create a hello world so what I will do is just to create Hello World now if you have worked with s or any other language before uh basically we we do multiple steps right but let me show you the code in Spring which will print hello world I'm I'm not going to explain

08:40

everything in this video how spring web works we have a separate section on that but just to show you how to build application I will get a class and I will name this class as hello I'll just simply say hello and then I will just return I will create a

08:57

method here and this method is responsible to print hello world on the screen so I will say public string I will simply say greet and this will return hello world a very simple method right nothing fancy for Server a simple class is just that

09:13

if you want this to work you simply say here rest controller and we have to map it with again I'm not explaining it here we have a detailed topic on this what is request mapping what is rest controller we'll talk about it at this point just

09:30

go for two annotations and say I will say slash so basically whenever you request for the homepage it will return the hello world that's what I want or maybe I can say hello world welcome to telescope okay cool and now let's run this how do

09:45

we run this so you go back to your application or the main file and simply say run behind the scene it will of course compile the code it will run this on a tomcat just have a look and when you run for the first time it will print

10:00

this spring uh pattern here you can change it if you want uh but we are concerned about this or we want to focus on this so Tomcat started on port number 880 nowhere externally I'm using Tomcat okay a very simple stuff and I'm saying run on 880 I got it how do I test it of

10:17

course you can use a rest client like Postman or I will just open the browser and here I will say Local Host colon 880 enter and if you can see we got the answer we got response which is Hello World welcome to the lco it's so simple

10:33

right and how much time it took me to run this of course I was talking to the camera and doing this so it will take it took a lot of time but if you want to do this you can do that in minutes so you got your application up and running in minutes that's not the case with spring framework and you will see that once we

10:49

start with spring later so this is spring boat behind the scene it is still spring framework now the question is is it better than spring of course right it will help you but there are certain issues with spring boot as well of course not a big issue one of the issue

11:05

is by default it will do a lot of stuff for you so it basically follows convention over configuration because in Spring we do a lot of configuration here it says I will give you stuff you tell me what you want I will give it to you and most of the time it also gives you certain things which you don't want

11:20

example if you expand this libraries here there are so many things maybe I will not even going to use this but spring boot says take it okay so that's one and next since it gives you a lot of default stuff if you want to configure then of course you have to do those configuration by yourself that means if

11:37

you want more control it is better to work with spring framework than spring boot again debatable uh personally I prefer spring boot if I want to work on a project I'm happy to do the configuration in Spring boot but yeah people might prefer spring framework for that reason it's still debatable but spring boot is awesome so yeah that's

11:55

one of the issue and um yeah that's about it I wanted to show you what is spring Boot and people who cry about Java being slow Java being wos spring boot is here it will make your work easy see you in the next video