#5 What is Spring Boot?

Telusko
30 Apr 202412:11

Summary

TLDRThis video introduces Spring Boot, a powerful framework that simplifies the configuration and deployment of Java applications. The speaker explains the traditional challenges of setting up Spring applications, such as object creation and server configuration with Tomcat. Spring Boot addresses these issues by embedding a Tomcat server and providing a quick start with minimal configuration. The tutorial demonstrates creating a simple 'Hello World' application with Spring Boot, showcasing its ease of use and rapid deployment capabilities. The video also touches on the trade-offs between Spring Boot's convention-over-configuration approach and the need for customization.

Takeaways

  • 🌟 Spring Boot is designed to simplify the bootstrapping and development of new Spring applications.
  • πŸ”§ Spring Boot handles a lot of the configuration automatically, reducing the need for manual setup compared to traditional Spring Framework applications.
  • πŸš€ Spring Boot allows for quick project setup and can get a project running in a matter of minutes, which was a challenge with the Spring Framework.
  • πŸ› οΈ Spring Boot includes an embedded server like Tomcat, eliminating the need for external server installations and configurations.
  • πŸ“¦ Spring Boot projects can be packaged as a JAR file, which can run standalone without the need for a WAR file and an external server.
  • 🌱 Spring Boot promotes the use of convention over configuration, which can speed up development but may also include dependencies that are not needed for every project.
  • πŸ“ The script mentions the use of 'start.spring.io' for generating new Spring Boot projects with specific configurations and dependencies.
  • πŸ”„ Spring Boot is built on top of the Spring Framework, and it is not a separate project but an additional layer that simplifies the process of building applications.
  • 🌐 The script demonstrates creating a simple 'Hello World' application using Spring Boot, showcasing the ease of creating and running a basic web service.
  • πŸ›‘ While Spring Boot is beneficial for quick setups, it may include unnecessary configurations and dependencies, which could be a drawback for those who prefer more control over their setups.
  • πŸ”‘ The choice between using Spring Boot and the Spring Framework depends on the developer's preference for ease of setup versus the need for more granular control over configurations.

Q & A

  • What is the main purpose of Spring Boot?

    -Spring Boot is designed to simplify the bootstrapping and development of new Spring applications, handling complex configurations and allowing for quick project setup and deployment.

  • How does Spring Boot differ from the Spring Framework?

    -Spring Boot is built on top of the Spring Framework, providing additional layers that simplify the process of building projects by handling configurations automatically and embedding a Tomcat server for web applications.

  • What is the significance of Spring Boot's embedded Tomcat server for web applications?

    -The embedded Tomcat server in Spring Boot allows developers to run their web applications without the need for an external server, which streamlines the deployment process and reduces the setup time.

  • Why might a developer choose to use Spring Framework over Spring Boot?

    -A developer might prefer the Spring Framework for more control over configurations and to avoid the automatic inclusion of dependencies that may not be needed for their specific project.

  • What is the role of 'start.spring.io' in creating a Spring Boot project?

    -'start.spring.io' is a website that provides an easy way to generate a Spring Boot project with the desired dependencies and configurations, speeding up the project creation process.

  • How does Spring Boot handle object creation in an application?

    -Spring Boot, like the Spring Framework, manages object creation through its dependency injection mechanism, allowing developers to specify which classes should have their objects created and managed.

  • What is the benefit of using Spring Boot for experimental projects or quick prototyping?

    -Spring Boot's simplified configuration and quick setup process make it ideal for experimental projects or quick prototyping, allowing developers to focus more on the application logic rather than setup and configuration.

  • What is the default packaging type for Spring Boot applications?

    -The default packaging type for Spring Boot applications is a JAR file, which includes an embedded server and allows for easier deployment and execution.

  • How does Spring Boot's convention over configuration approach affect the development process?

    -Spring Boot's convention over configuration approach provides developers with sensible defaults for many common tasks, reducing the need for explicit configuration and speeding up the development process.

  • What are some of the dependencies included in a Spring Boot project generated by 'start.spring.io'?

    -Some of the dependencies that might be included in a Spring Boot project are Spring Boot Starter Web, Jackson for JSON conversion, Micrometer for observability, and an embedded Tomcat server.

  • How can a developer test a simple Spring Boot application that returns 'Hello World'?

    -A developer can test a simple Spring Boot application by running the application and accessing the specified endpoint, such as 'localhost:8080', in a web browser or using a REST client like Postman.

Outlines

00:00

πŸ˜€ Introduction to Spring Boot and Its Advantages

The speaker, A Ready, welcomes viewers back and introduces the topic of Spring Boot, a framework designed to simplify the bootstrapping and development of new Spring applications. The video aims to receive 250 comments. The speaker explains that while the Spring framework is powerful for object creation and dependency management, it can be cumbersome for large projects due to its extensive configuration requirements. Spring Boot addresses this by reducing the need for configuration and allowing for quicker project setup. It is not a separate project but an additional layer on top of the Spring framework, making it easier to build applications by providing defaults and embedded servers like Tomcat. The speaker guides viewers on how to start a Spring Boot project using start.spring.io, emphasizing the ease and speed of getting a project up and running with minimal configuration.

05:00

πŸ› οΈ Setting Up a Spring Boot Project with Embedded Tomcat

This paragraph delves into the process of setting up a Spring Boot project with an embedded Tomcat server, eliminating the need for external server installations. The speaker demonstrates how to create a new Maven project using start.spring.io, selecting the appropriate Java version, packaging as a JAR file, and choosing necessary dependencies like Spring Web. The speaker also discusses the flexibility of Spring Boot, allowing developers to select only the components they need for their project. Once the project is generated and downloaded, the speaker shows how to import it into an IDE, such as IntelliJ Community Edition, and how the project comes with a pre-configured set of dependencies, including an embedded Tomcat server, which simplifies the deployment process. The speaker then creates a simple 'Hello World' REST controller to demonstrate the ease of creating and running a basic application in Spring Boot.

10:01

πŸš€ Running a Spring Boot Application and Its Trade-offs

The speaker concludes the video by running the 'Hello World' Spring Boot application, showcasing how quickly and easily a project can be executed with minimal setup. The application runs on an embedded Tomcat server on port 880, and the speaker tests it by accessing it through a web browser, successfully retrieving the 'Hello World' message. The speaker also discusses the trade-offs of using Spring Boot, such as the convention over configuration approach, which can sometimes include unnecessary components by default. However, the speaker expresses a preference for Spring Boot due to its ease of use and rapid development capabilities, while acknowledging that some developers may prefer the more granular control offered by the traditional Spring framework. The video ends with a reminder of Spring Boot's benefits in simplifying Java development and a teaser for the next video.

Mindmap

Keywords

πŸ’‘Spring Boot

Spring Boot is a framework built on top of the Spring Framework to simplify the bootstrapping and development of new Spring applications. It provides a set of pre-configured templates and starters that reduce the amount of initial setup required to start a new project. In the video, the speaker discusses how Spring Boot addresses the configuration problems of traditional Spring Framework applications, allowing developers to get a project running in just a few minutes.

πŸ’‘Spring Framework

The Spring Framework is a comprehensive programming and configuration model for modern Java-based enterprise applications. It provides a way to manage object creation and dependencies, which is referred to as Inversion of Control (IoC). In the video, the speaker explains that Spring Framework is powerful but can be complex to set up, which is why Spring Boot was introduced to streamline the process.

πŸ’‘Configuration

Configuration in the context of the video refers to the setup and initial arrangements needed to get a Spring application running. This includes specifying dependencies, setting up a server like Tomcat, and defining how objects are created and managed. The speaker contrasts the traditional Spring Framework's configuration process with the simplified setup provided by Spring Boot.

πŸ’‘Tomcat Server

Tomcat is an open-source Java Servlet Container developed by the Apache Software Foundation. It is used to serve Java-based web applications. In the video, the speaker mentions that traditional Spring web applications require an external Tomcat server to be installed and configured before the application can be run. However, Spring Boot simplifies this by including an embedded Tomcat server within the application.

πŸ’‘Embedded Tomcat

Embedded Tomcat is a feature of Spring Boot that allows a Tomcat server to be included within the application itself, eliminating the need for a separate server installation. This is highlighted in the video as one of the ways Spring Boot simplifies the deployment process for Java web applications.

πŸ’‘Maven Project

A Maven project is a project managed by Apache Maven, a build automation tool used primarily for Java projects. Maven handles the project's build process, dependencies, and documentation. In the video, the speaker uses Maven to create a new Spring Boot project through the start.spring.io website.

πŸ’‘Dependencies

Dependencies in a Java project are libraries or modules that the project requires to function. The speaker discusses how Spring Boot manages dependencies, including the automatic inclusion of necessary libraries for a web application, such as Jackson for JSON conversion and Micrometer for observability.

πŸ’‘@RestController

@RestController is an annotation in Spring Framework used to indicate that a class is a controller where every method returns a domain object directly (not a view). It is used to create RESTful web services. In the video, the speaker uses the @RestController annotation to create a simple 'Hello World' endpoint.

πŸ’‘@RequestMapping

@RequestMapping is a Spring Framework annotation used to map HTTP requests to controller methods. It is part of the Spring MVC module and is used to define the request path for a controller method. In the video, the speaker uses @RequestMapping to map the root URL to a method that returns 'Hello World'.

πŸ’‘Convention over Configuration

Convention over Configuration is a principle in software development where the software makes reasonable assumptions about the user's intent based on naming conventions rather than requiring the user to specify every detail through configuration files. Spring Boot follows this principle, as mentioned in the video, by providing sensible defaults and reducing the need for extensive configuration.

πŸ’‘start.spring.io

start.spring.io is a website provided by the Spring team that allows developers to generate a new Spring Boot project with pre-configured settings and dependencies. The speaker uses this website to demonstrate how quickly a new Spring Boot project can be created with the necessary dependencies for a web application.

Highlights

Introduction to Spring Boot and its purpose in simplifying the configuration process of Spring Framework applications.

The Spring Framework's role in object creation and dependency management within Java applications.

The limitations of Spring Framework in handling large numbers of classes and the need for selective object creation.

The necessity of configuring the Spring Framework through XML or property files to specify which classes to instantiate.

The requirement of a server like Tomcat for running web applications built with Spring, and the associated setup challenges.

The contrast between the quick setup of modern languages like Python or JavaScript and the initial complexity of setting up Java applications.

The introduction of Spring Boot as a solution to streamline the project setup and reduce configuration time.

Spring Boot is not a separate framework but an additional layer on top of the Spring Framework, simplifying the development process.

The ability of Spring Boot to automatically configure embedded servers like Tomcat, eliminating the need for external server installations.

The demonstration of creating a Spring Boot project using start.spring.io, a website that simplifies the project setup process.

The ease of selecting project dependencies and configurations through the start.spring.io interface.

The option to choose between a WAR or JAR packaging in Spring Boot, with the latter including an embedded Tomcat server.

The explanation of how Spring Boot's embedded server functionality allows for quicker deployment without the need for external servers.

The process of generating a Spring Boot project with specific dependencies and configurations using start.spring.io.

The simplicity of creating a 'Hello World' application in Spring Boot and running it with minimal setup.

The demonstration of running a Spring Boot application and accessing it via a web browser, showcasing the ease of use.

The comparison between Spring Boot and Spring Framework in terms of ease of use, control, and default configurations.

The acknowledgment of potential issues with Spring Boot's convention over configuration approach and its impact on customization.

The final thoughts on the benefits of Spring Boot for rapid application development and its impact on Java's reputation for being slow.

Transcripts

play00:00

welcome back aliens my name is a ready

play00:01

and in this video we'll talk about

play00:03

spring boot so before we talk about

play00:05

spring boot the target for this video is

play00:07

250 comments now till this point we have

play00:09

talked about spring framework right and

play00:11

we are excited to understand how this

play00:13

framework works and whatever things it

play00:16

promises how it deals with that so yes

play00:19

spring framework is amazing right and

play00:21

whatever application we are going to

play00:22

build now is with the help of spring so

play00:24

let's say you want to build an

play00:26

application this can be anything in the

play00:28

world even it can be a huge application

play00:32

or it can be a application for hello

play00:35

world typically what happens is when you

play00:37

want to build the application of course

play00:39

you have your Java code with you and

play00:41

then to make it work spring says hey you

play00:44

know doesn't matter how many classes you

play00:46

have I will take care of the object

play00:47

creation and you are quite happy because

play00:50

now you don't have to worry about the

play00:51

objects spring says I will take care of

play00:53

it so let's say in your application you

play00:55

have you have three classes and you say

play00:57

hey Spring create object of this three

play01:00

classes and spring is happy to do that

play01:02

so let's say in your application now you

play01:03

have 100 or thousand classes can spring

play01:06

handle all the objects of course it can

play01:09

but the question is do you want spring

play01:11

to handle all the classes you know most

play01:13

of the time we don't even want the

play01:15

object of few classes let's say you have

play01:18

lot of classes here and out of all these

play01:20

classes you need objects of only few

play01:22

classes how do you talk to your spring

play01:24

framework by saying hey don't create

play01:27

objects for everything I don't want all

play01:29

those things I just want few spring says

play01:32

okay tell me which one you want and

play01:34

that's where when you talk to the

play01:36

framework we have to do that in the

play01:38

configuration file it can be XML file or

play01:41

it can be a property file but you have

play01:43

to talk to the framework that means just

play01:47

because you're using a framework you

play01:48

will not be able to run your code in the

play01:50

first go you have to first do the

play01:53

configuration next part let's say if you

play01:55

are building a web application now if

play01:56

you want to run your web application

play01:59

basically you need a server in terms of

play02:02

java uh we need something called a

play02:04

tomcat server of course we have multiple

play02:06

options let's say if you want if you're

play02:08

building a web application in Spring you

play02:10

need to have a tomcat server that means

play02:12

in your machine even before you run your

play02:14

code you have to make sure that you have

play02:16

installed Tomcat you have configured

play02:19

Tomcat then only you can run your

play02:21

application so you'll be saying hey

play02:23

what's wrong with that I mean of course

play02:25

we can do configuration we can install

play02:27

Tomcat see the problem is when you have

play02:30

a long project it makes sense to spend

play02:32

few hours or days doing the

play02:35

configuration because the project will

play02:36

go for a year but what if you are doing

play02:38

some experiment what if you want to get

play02:41

started in few minutes see most of the

play02:43

languages nowadays they are doing that

play02:45

if you talk about python or JavaScript

play02:48

they have their Frameworks and if you

play02:50

want to at least print hello world you

play02:52

can do that in minutes now this is what

play02:55

spring was lagging way back and Java was

play02:58

lagging way back and that's where we got

play03:00

something called a spring boot now

play03:03

spring boot says all your problems of

play03:05

configuration let me take care of it

play03:08

what if you can get your project running

play03:11

in few minutes and that's what spring

play03:13

boot gives you it's not a new project is

play03:15

there from a long time but it basically

play03:18

solves your problem of building a

play03:20

project in less time so does it means

play03:22

that spring boot is different from

play03:24

Spring framework not exactly see

play03:27

underlying it's all spring framework

play03:29

right on top of that you have one more

play03:32

layer of spring boot so you can actually

play03:34

build application directly using spring

play03:36

framework or if you want to make it easy

play03:39

you can use spring boot again that's an

play03:40

optional stuff but this optional thing

play03:43

is very very important and uh it will

play03:46

make your work faster so basically we

play03:48

can use a spring boot which is a open

play03:50

unated framework which means it will

play03:52

give you certain things the way it wants

play03:54

and you can simply use it to run your

play03:56

application let me show you how what I'm

play03:58

talking about so let's say if I go to

play04:00

the spring.io the official website and

play04:02

instead of this website if I just say

play04:05

start. spring.io it will take you to a

play04:08

website now see when you talk about

play04:10

building a project in different idees we

play04:12

have an option of directly saying a new

play04:14

project and you can create a spring

play04:15

project in spring project basically you

play04:17

create a mavin project again we'll see

play04:19

that in in sometime or in the upcoming

play04:21

videos but basically you have to create

play04:23

a m project at the spring dependency a

play04:25

lot of different steps right inell idea

play04:28

ultimate version gives you a an option

play04:30

of creating a spring boot project

play04:31

directly but since we are not going to

play04:33

go for the ultimate version we don't

play04:34

want to pay for it we have a good

play04:36

alternative what you can do is you can

play04:38

go to Spring Riser which is this website

play04:40

start. spring.io and you can mention

play04:43

what kind of project you are building so

play04:44

I'm building a MAV project this is a

play04:45

build tool the language I'm going for is

play04:47

Java and then the spring boot version so

play04:50

this is update version so you can see we

play04:51

have 3.2.5 we can even go for the rc1

play04:55

but I just want to stick to the stable

play04:57

one which is uh 3.2.5 and depend upon

play05:00

when you're watching this you can just

play05:01

use that particular version the group I

play05:04

will say com. telescope and the project

play05:06

name is let's say uh demo app and then

play05:09

the packaging is I'm going for Java now

play05:12

this this is where the beauty lies you

play05:13

know if you talk about a spring

play05:14

framework or any web application in Java

play05:17

you can create a project and if you want

play05:19

to deploy it on the cloud basically you

play05:21

create a v file so v v stands forb web

play05:24

archive and then you basically push your

play05:26

W file in the Tomcat to run it multiple

play05:29

steps right spring boot says don't worry

play05:31

you can create a jar file but the

play05:33

problem is jar file we cannot run jar

play05:35

file on the Tom Cat then how it would

play05:38

work what if you don't need external Tom

play05:41

Cat what if the project itself has a

play05:44

tomcat I mean that will be awesome right

play05:47

so basically spring boot says if you

play05:48

want to build a web project you will get

play05:50

a embedded tom cat so I will select jar

play05:54

and I'll show you what I'm I'm talking

play05:56

about and then I can select my Java

play05:58

version so in this machine I got Java 21

play06:00

so I will go with that it is LTS version

play06:02

so it's safe to use and dependency so

play06:05

what are things we need so of course if

play06:06

you remember when we talked about spring

play06:08

framework I mentioned that there are

play06:10

multiple projects inside spring and we

play06:12

don't need all depending upon your use

play06:14

case you will choose one so I will click

play06:16

on ADD

play06:17

dependencies so you can see there are

play06:19

lot of options here to choose from and

play06:22

you don't have to know everything uh use

play06:24

whatever you need example here I want to

play06:27

build a web application so I will simply

play06:28

say uh spring web if you want to add

play06:31

database connectivity you can also add

play06:33

uh jpa but we don't need that at this

play06:35

point uh if you want to get a longbox

play06:38

support you can choose that if you want

play06:40

to uh use graphql you can use that uh so

play06:44

as I mentioned there are so many options

play06:46

here but I just want to stick to one

play06:47

which is bring web and click on generate

play06:50

now before I click on generate I will

play06:52

show you how this configuration looks

play06:54

like so it will give you the entire

play06:55

configuration we can see we got a

play06:57

dependency which is spring boot stter

play06:59

web here the Java version is 21 this is

play07:02

my project name and this is the spring

play07:04

boot version which we are using and

play07:05

behind this it will use spring framework

play07:07

I will show you the code so click on

play07:09

download you can even click on the uh

play07:12

generate here so you can see in the

play07:13

downloads I got this project which is

play07:15

demo app what I will do is I will just

play07:18

unzip it so unzipping is done on the

play07:20

other screen but uh I will just open

play07:21

that project now in my ID now you can

play07:24

use any ID here you can use Eclipse you

play07:26

can use vs code you can use intellig

play07:28

idea Community version version or theate

play07:30

version so I'm using a community version

play07:32

here just to show you the proof I will

play07:34

click on not update I will click on

play07:37

about and you can see this is a

play07:38

community version and I will click on

play07:40

open the project so this is the project

play07:42

which I've downloaded click on open and

play07:46

voila you got your project and the

play07:48

beauty is if I expand the dependencies I

play07:51

think it will take some time to download

play07:52

okay download it too fast and you can

play07:55

see it added so many dependencies here

play07:58

uh the for the Jackson for Json

play08:00

conversion uh we got uh micrometer for

play08:04

observing we got Tomcat you can see we

play08:06

got embed Tomcat so basically you don't

play08:08

need to have the external Tom Cat here

play08:10

and if you go down uh we got spring boot

play08:13

but also we got spring framework you can

play08:15

see we got spring code so all the things

play08:17

which are spring required for spring

play08:18

code or spring project we got it here

play08:21

okay uh let me just drop it here and now

play08:23

let me create a hello world so what I

play08:26

will do is just to create Hello World

play08:28

now if you have worked with s or any

play08:30

other language before uh basically we we

play08:33

do multiple steps right but let me show

play08:35

you the code in Spring which will print

play08:37

hello world I'm I'm not going to explain

play08:40

everything in this video how spring web

play08:42

works we have a separate section on that

play08:44

but just to show you how to build

play08:45

application I will get a class and I

play08:48

will name this class as

play08:51

hello I'll just simply say hello and

play08:54

then I will just return I will create a

play08:57

method here and this method is

play08:58

responsible to print hello world on the

play09:01

screen so I will say public string I

play09:03

will simply say

play09:06

greet and this will return hello world a

play09:09

very simple method right nothing fancy

play09:10

for Server a simple class is just that

play09:13

if you want this to work you simply say

play09:16

here rest controller and we have to map

play09:21

it with again I'm not explaining it here

play09:24

we have a detailed topic on this what is

play09:26

request mapping what is rest controller

play09:28

we'll talk about it at this point just

play09:30

go for two annotations and say I will

play09:31

say slash so basically whenever you

play09:34

request for the homepage it will return

play09:35

the hello world that's what I want or

play09:37

maybe I can say hello world welcome to

play09:40

telescope

play09:41

okay cool and now let's run this how do

play09:45

we run this so you go back to your

play09:46

application or the main file and simply

play09:49

say run behind the scene it will of

play09:52

course compile the code it will run this

play09:55

on a tomcat just have a look and when

play09:58

you run for the first time it will print

play10:00

this spring uh pattern here you can

play10:03

change it if you want uh but we are

play10:05

concerned about this or we want to focus

play10:07

on this so Tomcat started on port number

play10:09

880 nowhere externally I'm using Tomcat

play10:12

okay a very simple stuff and I'm saying

play10:14

run on 880 I got it how do I test it of

play10:17

course you can use a rest client like

play10:19

Postman or I will just open the browser

play10:23

and here I will say Local Host colon 880

play10:25

enter and if you can see we got the

play10:28

answer we got response which is Hello

play10:30

World welcome to the lco it's so simple

play10:33

right and how much time it took me to

play10:36

run this of course I was talking to the

play10:38

camera and doing this so it will take it

play10:40

took a lot of time but if you want to do

play10:42

this you can do that in minutes so you

play10:44

got your application up and running in

play10:45

minutes that's not the case with spring

play10:47

framework and you will see that once we

play10:49

start with spring later so this is

play10:51

spring boat behind the scene it is still

play10:54

spring framework now the question is is

play10:57

it better than spring of course right it

play10:59

will help you but there are certain

play11:01

issues with spring boot as well of

play11:03

course not a big issue one of the issue

play11:05

is by default it will do a lot of stuff

play11:07

for you so it basically follows

play11:09

convention over configuration because in

play11:11

Spring we do a lot of configuration here

play11:13

it says I will give you stuff you tell

play11:15

me what you want I will give it to you

play11:17

and most of the time it also gives you

play11:19

certain things which you don't want

play11:20

example if you expand this libraries

play11:22

here there are so many things maybe I

play11:24

will not even going to use this but

play11:26

spring boot says take it okay so that's

play11:29

one and next since it gives you a lot of

play11:32

default stuff if you want to configure

play11:34

then of course you have to do those

play11:35

configuration by yourself that means if

play11:37

you want more control it is better to

play11:39

work with spring framework than spring

play11:41

boot again debatable uh personally I

play11:43

prefer spring boot if I want to work on

play11:45

a project I'm happy to do the

play11:46

configuration in Spring boot but yeah

play11:48

people might prefer spring framework for

play11:50

that reason it's still debatable but

play11:52

spring boot is awesome so yeah that's

play11:55

one of the issue and um yeah that's

play11:57

about it I wanted to show you what is

play12:00

spring Boot and people who cry about

play12:03

Java being slow Java being

play12:06

wos spring boot is here it will make

play12:09

your work easy see you in the next video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Spring BootJavaApplicationDevelopmentTomcatConfigurationWeb AppFrameworkProject SetupEmbedded Server