0% found this document useful (0 votes)
3 views

Spring boot

The document outlines the process of creating a Spring Boot application, highlighting the advantages of Spring Boot over traditional Spring Framework setups, such as auto-configuration and embedded servers. It discusses essential components like the Spring Initializr for project generation, Spring Data JPA for database interactions, and annotations for defining controllers and services. Additionally, it explains the role of Maven in managing dependencies and the importance of the @SpringBootApplication annotation for bootstrapping the application.

Uploaded by

Vivan Vish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Spring boot

The document outlines the process of creating a Spring Boot application, highlighting the advantages of Spring Boot over traditional Spring Framework setups, such as auto-configuration and embedded servers. It discusses essential components like the Spring Initializr for project generation, Spring Data JPA for database interactions, and annotations for defining controllers and services. Additionally, it explains the role of Maven in managing dependencies and the importance of the @SpringBootApplication annotation for bootstrapping the application.

Uploaded by

Vivan Vish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Spring boot:

Basic Spring project:

Issues with spring framework:

 Create maven project


 Set server, install ,add server, and run project with targeted runtime
 Add dependencies in pom.xml
 web.xml -> dispatcher server configures and dispatcher servlet name -server.xml create
add view resolver, data source, session factory and all
 then create model, view, controller develop need to be done and to reach that
we need to add above steps.
If above can be automatic then we can work easily to spring boot came into picute.

Pom.xml dependencies all added in spring.


But spring boot automatic dependencies features been added.
In web.xml dispatcher servlet configured but cannot be done in spring boot.
DispatcherServlet handles an incoming HttpRequest,
delegates the request, and processes that request
according to the configured HandlerAdapter interfaces
that have been implemented within the Spring
application along with accompanying annotations
specifying handlers, controller endpoints, and
response objects.
1) Spring boot gives us auto configurations.
2) Spring boot starters (dependency pom.xml and others) it provide different starters
For web application wanted to develop rest clients and all it give spring boot starter web
package will be provided if selected backend dependencies will be added by selecting
just spring boot starter web package.
3) Embedded server automatic inbuild server can be added
4) CLI(command line interface) -> only not IDE but can support through CLI test and run
5) Actuators -> check health of application (resource utilization metrics) inbuild can be
checked (how good application run)

Spring tool suite -> need to have (spring boot projects) or use eclipse

Have rest client tool we use postman tool.

Springboot:
@SpringbootApplication: it contains inbuild all annotations all spring boot configuration
required are added by spring boot application.

Above screenshot starts the spring boot application.


Spring boot:

Makes it easy to create standalone production grade spring-based applications that you
can just run.

Spring boot?

Opinionated -> give certain configurations to us.

Convention over configuration -> default data given

Standalone-> when build spring we build jar or war file to servlet container.

Spring boot give standalone container ready to run(no need servlet container)

Production ready -> take and deploy

Create Spring boot:

Add parent in pom.xml

It declares our project is child of parent project.

Courseapi project is child of spring boot starter parent.

Convention over configuration: for 80% use case spring boot provide the default
configuration.

Spring boot team created a project called as SPRING-BOOT-STARTER-PARENT


All the default maven config placed here as it contains maven configurations.

Thanks to maven child inheritance.

Add parent in pom.xml.

For creating web application listen to rest services

They are bunch of jars import for spring application

Identify list and add it in pom.xml

For web application we add dependencies

Spring-boot-starter-web

To increase java version we add in pom.xml


Now building spring boot application:

To know its a spring application we have annotation as

@SpringBootApplication

Public class CourseApiAPP{

Public static void main(String[] args){

SpringApplication.run(CourseApiAPP.class, args);

}}

Tomcat started:

SpringApplication.run(App.class,args);
Spring boot starter create application context

Performs class path scan: this is service, this is controller

depend on marker treat as service and controller.

This classes contains other meta based and behave based on that for that need to scan path

It start tomcat server

Controller: what URL mapping and what should happen request comes too.
Write method when called.

@RestController -> provide http response to the request.

@RequestMapping: take parameter which is URL this method need to map to which is hello

It tells when its request /hello above method should be executed and return the value.

Returning Objects from Controller:


Topic controller list the topics
Spring MVC Controller:

REST API:
@Service: it’s a business service

@autowire: need dependency injection


TopicService:
Spring Initializer:
Spring Initializr:

Spring Initializr is a web application that can generate a Spring Boot project
structure for you
Spring Initializr provides an extensible API to generate JVM-based projects,
and to inspect the metadata used to generate projects, for instance to list the
available dependencies and versions.
Run spring groovy script:

Bootstrap spring boot application

Nano app.groovy

In that create controller class.


Run file using below command

. /spring run app.groovy

Above script create spring boot application.


Spring boot connect to DB return results

Spring Data JPA:

JPA(Java persistence API): allows to do ORM(object relational mapping)

When connect java application to relational database get results and convert to object
instance.

ORM map entity classes to sequel tables.

JPA help to configure entity classes and give to framework so that it does rest

Convert read queries to class objects.

Add Spring Data JPA in pom.xml


Below dependencies added in pom.xml

Database added

In relational database one should be primary key

@column should be primary key

@Entity annotation specifies that the class is an entity and is


mapped to a database table.
What is Hibernate and JPA in spring boot?
JPA is a specification and defines the way to manage relational database data
using java objects. Hibernate is an implementation of JPA.
https://www.youtube.com/watch?v=_Jnu_jHfQbM&list=PLqq-
6Pq4lTTbx8p2oCgcAQGQyqN8XeA1x&index=31

You might also like