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

Spring Boot Framework

The Spring Boot Framework is a Java-based framework designed for creating stand-alone, production-grade Spring applications with features like auto-configuration and built-in web servers. It simplifies development through dependency injection and integration with other Java frameworks, while also providing a structured architecture with presentation, business, persistence, and database layers. Additionally, it includes tools for RESTful web services, application properties management, and monitoring through the Spring Boot Actuator.

Uploaded by

Dhanush kuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Spring Boot Framework

The Spring Boot Framework is a Java-based framework designed for creating stand-alone, production-grade Spring applications with features like auto-configuration and built-in web servers. It simplifies development through dependency injection and integration with other Java frameworks, while also providing a structured architecture with presentation, business, persistence, and database layers. Additionally, it includes tools for RESTful web services, application properties management, and monitoring through the Spring Boot Actuator.

Uploaded by

Dhanush kuna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 158

Spring Boot Framework

Day 1
What is Spring Boot Framework?

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications. It’s a Java-based
framework.

It offers several plug-ins.

It provides production-ready features such as metrics, health checks, and externalized configuration.

There is no requirement for XML configuration.


All kinds of applications can be designed using spring boot.

For web applications, spring boot provides in built web servers (tomcat).

Many things are auto-configured.

Each application can have its own server.


Spring Spring Boot
Spring framework is a java EE framework that is used Spring Boot framework is mainly used to develop
to build applications. REST API’s

Its goal is to make Java EE (Enterprise Edition) Spring Boot provides the RAD(Rapid Application
development easier, allowing developers to be more Development) feature to the Spring framework for
productive. faster application development.

Spring framework helps to create a loosely coupled Spring Boot helps to create a stand-alone
application. application.

In the Spring framework to test the Spring Project, Spring Boot offers built-in or embedded servers such
we need to set up the servers explicitly. as Tomcat and jetty.
Why we are using Spring Boot Framework?
The dependency injection approach is used in Spring Boot.

It contains powerful database transaction management capabilities.

It simplifies integration with other Java frameworks like JPA/Hibernate ORM, Struts, etc.

It reduces the cost and development time of the application.


Prerequisite of Spring Boot

Spring Tool Suite (STS) or Eclipse or Intelij IDE

Java 1.8

Spring Boot version 3.0

PostgreSQL
Spring Boot Framework

Day 2
Spring Boot Features :

Web Development

Spring Application

Properties Files

YAML Support

Logging

Security
Web Development :

Spring Boot is great for building web applications.

we can easily create an HTTP application with built-in servers like Tomcat, Jetty, or Undertow.

Use the spring-boot-starter-web module to start and run your application quickly.
Spring Boot Application :

The Spring Boot Application class makes it easy to start a Spring application.

we can start the application from the main method using a static run() method.
Properties Files :

Spring Boot offers many application properties.

we can use those properties in our project's properties file.

The properties file lets you set configurations like server-port=8082.

It helps organize and manage application settings.


YAML Support :

It provides a convenient way of specifying the hierarchical configuration.

It is a superset of JSON.

The SpringBootApplication class automatically supports YAML.

It is an alternative to the properties file.


Logging :

Spring Boot uses Common Logging for its internal logs.

Logging dependencies are managed automatically.

Avoid changing logging dependencies unless customization is required.


Security :

Spring Boot applications are spring-based web applications.

So, it is secure by default with basic authentication on all HTTP endpoints.

A rich set of Endpoints is available to develop a secure Spring Boot application.


Spring Boot Framework

Day 3
Spring Boot
Architecture
There are four layers in Spring Boot are as follows:

Presentation Layer

Business Layer

Persistence Layer

Database Layer
Presentation Layer:

The presentation layer handles the HTTP requests, translates the JSON parameter to an object,
authenticates the request, and transfers it to the business layer.

In short, it consists of views i.e., the frontend part.

Business Layer:

The business layer handles all the business logic.

It consists of service classes and uses services provided by data access layers.

It also performs authorization and validation.


Persistence Layer:

The persistence layer contains all the storage logic

It translates business objects to and from database rows.

Database Layer:

In the database layer, CRUD (create, retrieve, update, delete) operations are performed.
The architecture of Spring Boot is similar to Spring MVC, but there is no need for DAO and DAOImpl classes.

It creates a data access layer and performs CRUD operations.

The client makes HTTP requests (PUT or GET).

The request goes to the controller, which maps and handles it, calling the service logic if needed.

The service layer performs all business logic on the data, which is mapped to JPA with model classes.
Spring Boot Framework

Day 4
What is Spring MVC?

Spring MVC is a Java framework used to build web-based applications.

So, Spring MVC is an integrated version of the Spring framework and Model View Controller.

It has all the basic features of the core Spring framework like Dependency Injection and Inversion of Control.

The MVC pattern segregates the application’s different aspects (input logic, business logic, and UI logic) while
providing a loose coupling between these elements.
The Model contains the core data of the application. In general, they consist of POJO (Plain Old Java Object).

The View is responsible for rendering the model’s data, and it generates HTML output that the client’s browser
can interpret.

The Controller contains the business logic of the application.

Spring MVC is built around the Dispatcher Template that handles the HTTP requests and responses.
How does Spring MVC Works?

The client system sends an HTTP request to a specific URL.

Dispatcher Servlet, configured in the web.xml file, receives the request.

It then passes the request to a specific controller by finding it using Handler Mapping depending on the URL
requested using @RequestMapping and @Controller annotations.

Spring MVC Controller executes the business logic and then returns a logical view name and model to
Dispatcher Servlet.
The Dispatcher Servlet finds the right view (like Excel, Freemarker, JSP) to use based on configured rules.

Finally, this formatted output is sent back to the client as a response.


What is Spring Boot?

Spring Boot is another popular Java framework used for building applications.

It mainly focuses on creating standalone applications.

It is an extended version of the Spring framework that helps to reduce the development time.

Spring Boot is great for enterprise applications

There are four layers in Spring boot;

Presentation layer

Business layer

Persistence layer

Database layer
The workflow goes like:

The client makes the HTTP requests.

This request goes to the controller, and the controller maps and handles it.

The request is passed on to the service layer where all the business logic is performed on the data that is
mapped to JPA with model classes.

As a result, a response is returned to the user if no error occurred.


Spring Boot Framework

Day 5
How to create Spring Boot Application

&

Spring boot Annotations


Spring Initializer

Spring Boot STS IDE

Spring Boot CLI


@Bean:

Indicates that a method produces a bean to be managed by the Spring container.

@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder(); //BCryptPasswordEncoder function
provided by the spring security
}
@SpringBootApplication

A single @SpringBootApplication annotation is used to enable the following annotations:

@EnableAutoConfiguration: It enables the Spring Boot auto-configuration mechanism.

@ComponentScan: It scans the package where the application is located.

@Configuration: It allows us to register extra beans in the context or import additional configuration classes.
@Required: It applies to the bean setter method.

It indicates that the annotated bean must be populated at configuration time with the required property,
else it throws an exception BeanInitilizationException.

public class Machine


{
private Integer cost;

@Required
public void setCost(Integer cost)
{
this. cost = cost;
}

public Integer getCost()


{
return cost;
}
}
@Component:

It is a class-level annotation.

Turns the class into a spring bean at the auto-scan time.

@Component
public class Student
{
.......
}
@Autowired :

Injecting the application parts together, on the fields, constructors, or methods


in a component.

@Component
public class Customer
{

private Person person;

@Autowired
public Customer(Person person)
{
this.person=person;
}

}
@Controller: The @Controller is a class-level annotation.

The @Controller annotation is a special type of @Component that is used to handle web requests and show
web pages.

It is mostly used with @RequestMapping annotation.

@Controller
@RequestMapping("books")
public class BooksController
{
@RequestMapping(value = "/
{name}", method = RequestMethod.GET)
public Employee getBooksByName()
{
return booksTemplate;
}
}
@Service:

It is also used at the class level. It tells the Spring that the class contains the business logic.

package com.java;

@Service
public class TestService
{
public void service1()
{
//business code
}
@Repository:

The repository is a DAOs (Data Access Object) that access the database directly.

The repository does all the operations related to the database.

package com.java;

@Repository
public class TestRepository
{
public void delete()
{
//persistence code
}
}
@RequestMapping: It is used to map web requests.

It has many optional elements like consumes, header, method, name, params, path, produces, and value.

We use it with the class as well as the method.

@Controller
public class BooksController
{
@RequestMapping("/computer-science/
books")
public String getAllBooks(Model model)
{
//application code
return "bookList";
}
@GetMapping: It maps the HTTP GET requests on the specific handler method. It is used to create a web
service endpoint that fetches It is used instead of using: @RequestMapping(method = RequestMethod.GET)

@PostMapping: It maps the HTTP POST requests on the specific handler method. It is used to create a web
service endpoint that creates It is used instead of using: @RequestMapping(method = RequestMethod.POST)

@PutMapping: It maps the HTTP PUT requests on the specific handler method. It is used to create a web
service endpoint that creates or updates It is used instead of using: @RequestMapping(method =
RequestMethod.PUT)
@DeleteMapping:

It maps the HTTP DELETE requests on the specific handler method.


It is used to create a web service endpoint that deletes a resource.
It is used instead of using: @RequestMapping(method = RequestMethod.DELETE)

@RequestBody:

It is used to bind HTTP requests with an object in a method parameter.


Internally it uses HTTP Message Converters to convert the body of the request.
When we annotate a method parameter with @RequestBody,
The Spring framework binds the incoming HTTP request body to that parameter.
@ResponseBody: It tells the Spring Boot Framework to serialize a return an object into JSON and XML
format.

@PathVariable: It is used to extract the values from the URI. It is most suitable for the RESTful web service,
where the URL contains a path variable. We can define multiple @PathVariable in a method.

@RestController:
It can be considered as a combination of @Controller and @ResponseBody annotations.
The @RestController annotation is itself annotated with the @ResponseBody annotation.
It eliminates the need for annotating each method with @ResponseBody.
Spring Boot Framework

Day 6
Spring Boot Application Properties:

Spring Boot Framework comes with a built-in mechanism for application configuration using a file
called application.properties.

It is located inside the src/main/resources folder.

Spring Boot provides various properties that can be configured in the application.properties file.

The properties have default values. We can set a property(s) for the Spring Boot application.

Spring Boot also allows us to define our own property if required.


Example of application.properties

#configuring application name


spring.application.name = demoApplication

#configuring port
server.port = 8081
YAML Properties File

Spring Boot provides another file to configure the properties is called yml file.

The Yaml file works because the Snake YAML jar is present in the classpath.

Instead of using the application.properties file

we can also use the application.yml file, but the Yml file should be present in the classpath.
Example of application.yml

spring:
application:
name: demo Application

server:
port: 8081
Spring Boot Property Categories:

There are sixteen categories of Spring Boot


Property are as follows:

• Templating Properties
• Core Properties • Server Properties
• Cache Properties • Security Properties
• Mail Properties • RSocket Properties
• JSON Properties • Actuator Properties
• Data Properties • DevTools Properties
• Transaction Properties • Testing Properties
• Data Migration Properties
• Integration Properties
• Web Properties
Spring Boot Framework

Day 7
Spring Boot Rest Concept
All kinds of applications can be designed using spring boot .

For web applications spring boot provides built in web servers (tomcat) .

Spring boot is openionated .

Many things are auto configured . Each application can have its own server
Rest : - Representational state transfer Data received from the server depends on URL.

URL represents a particular page Whenever we change URL display to a new page.

Data formats : XML format

JSON format
XML Format :

<employee>

<empId> 100 </empId>


<empName> 'saddam’ </empName>

</employee>

XML file is quite bulky that’s why using JSON


JSON Format : Java script object notation

Single Object : { "emp Id " : 10,"name" : " saddam " }

Multiple Object : [

{ "emp Id " : 10,"name" : " saddam " }


{ "emp Id " : 20,"name" : " Hussain " }
{ "emp Id " : 30,"name" : " Naveen " }

]
How to create spring boot rest application project ?

create spring boot starter project with following dependencies

spring web

dev tools
spring web is using means we are seeing the data in web pages based on URL

spring boot dev tools whenever makes the changes in code we can save the code that's it
automatic restart the code without using the stopping process

This is the advantages of spring boot dev tool


Spring Boot Framework

Day 8
Basic Spring Boot Application creation

Video Link : https://youtu.be/domBd8sNowc


Spring Boot with Lombok Dependency
Advantages

Video Link : https://youtu.be/sbnXhixqY3I


Difference between @Pathvariable and @RequestParam
Annotations

Video Link : https://youtu.be/Ghd8llQ9mD8


Spring Boot Framework

Day 9
Spring Boot Data JPA
Create Entity classes with annotations

@Entity
@Id
@OneToOne
@OneToMany etc.,

we need to provide database details in application.properties file


Create repository interface and extending below interfaces.

Crud repository interface

Jpa repository interface(which provide all jpa methods)


Spring fox swagger

swagger is a documentation tool for rest application

swagger provides excellent UI for testing rest application spring boot does not provide swagger dependency
we need to add the swagger 2 and swagger dependencies

add @EnableSwagger2 annotation to the main class

with swagger we can test rest application using any normal browser
url's :

http://localhost:port number/v2/api-docs

http://localhost:port number/swagger-ui-html

We can use postman or swagger anything


Spring Boot Framework

Day 10
Spring Boot exception
handling
@controllerAdvice :-

It is the class which handles all the Global exceptions in the application.

It can have methods to handle different exceptions.

When exception happen or occurs anywhere in the application controller


advice is handling.

In controller advice class we need to write

@ExceptionHandler(Studentnotfoundexception.class) annotation in each


method.
Spring Boot data
validation
Spring data validation :-

check the data sent by the client.

Client sends the data in Json format.

Json is translated into Java object in the controller.

While translating we need to check the data.


Steps :-
add validation dependency.

use validation annotations in entity classes.

In the controller use @ valid annotation along with @RequestBody.

@Valid annotation makes it possible to check the validation errors.

If validation fails method argument not valid exception is thrown.

Controller advice should handle these exception


Exception Handling and Data validation

Video link : https://youtu.be/cPbNppp-9rs


Spring Boot Framework

Day 11
Spring Boot Starter
Actuator
Spring Boot Actuator is a sub-project of the Spring Boot Framework.

It includes a number of additional features that help us to monitor and manage the Spring Boot application.

It contains the actuator endpoints (the place where the resources live).
We can use HTTP and JMX endpoints to manage and monitor the Spring Boot application.

If we want to get production-ready features in an application, we should use the Spring Boot actuator.

Spring Boot Actuator Features

There are three main features of Spring Boot Actuator:

Endpoints

Metrics

Audit
Endpoint:

The actuator endpoints allows us to monitor and interact with the application.

Spring Boot provides a number of built-in endpoints. We can also create our own endpoint.

We can enable and disable each endpoint individually.

Most of the application choose HTTP, where the Id of the endpoint, along with the prefix of /actuator, is
mapped to a URL.

For example, the /health endpoint provides the basic health information of an application.

The actuator, by default, mapped it to /actuator/health.


Metrics:

Spring Boot Actuator provides dimensional metrics by integrating with the micrometer.

The micrometer is integrated into Spring Boot.

It is the instrumentation library powering the delivery of application metrics from Spring.

It provides vendor-neutral interfaces for timers, gauges, counters, distribution summaries, and long task
timers with a dimensional data model.
Audit:

Spring Boot provides a flexible audit framework that publishes events to an AuditEventRepository.

It automatically publishes the authentication events if spring-security is in execution.


Enabling Spring Boot Actuator

We can enable actuator by injecting the dependency spring-boot-starter-actuator in the pom.xml file.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
Id Usage Default
actuator It provides a hypermedia-based discovery page for the other endpoints. It True
requires Spring HATEOAS to be on the classpath.
auditevent It exposes audit events information for the current application. True
s
autoconfig It is used to display an auto-configuration report showing all auto- True
configuration candidates and the reason why they 'were' or 'were not'
applied.
beans It is used to display a complete list of all the Spring beans in your True
application.
configprop It is used to display a collated list of all @ConfigurationProperties. True
s
dump It is used to perform a thread dump. True
env It is used to expose properties from Spring's ConfigurableEnvironment. True
flyway It is used to show any Flyway database migrations that have been applied. True
health It is used to show application health information. False
info It is used to display arbitrary application info. False
loggers It is used to show and modify the configuration of loggers in the application. True
liquibase It is used to show any Liquibase database migrations that have been True
applied.
metrics It is used to show metrics information for the current application. True
mappings It is used to display a collated list of all @RequestMapping paths. True
shutdown It is used to allow the application to be gracefully shutdown. True
For Spring
Id Description Default MVC, the
docs It is used to display documentation,
including example requests and responses
False following
for the Actuator's endpoints. additional
heapdump It is used to return a GZip compressed
hprof heap dump file.
True endpoints are
jolokia It is used to expose JMX beans over HTTP True
used.
(when Jolokia is on the classpath).

logfile It is used to return the contents of the True


logfile.

prometheu It is used to expose metrics in a format that True


s can be scraped by a prometheus server. It
requires a dependency on micrometer-
registry- prometheus.
Spring Boot Framework

Day 12
Application . properties file

v/s

Application . yml file


Application . properties file :

Data is stored in key-value fashion.

Sequential format

Advantages :

Easy to modify

Disadvantages :

Repetition in keys

On increase in properties file, it becomes difficult to understand the keys and value.
Application . yml file : Disadvantages :

Yml stands for yet another markup language. Complex indentation formatting.

Stores data in key-value pair fashion.

Hierarchical format.

Advantages :

Easy to modify.

Easy to understand as it follows hierarchical


approach

No repetitions in keys.

Multi language support like java, python etc.,

We can have array, list, and map also in yaml.


Spring Boot Framework

Day 13
@Qualifier vs @Primary Annotations with
Examples
We can use @Qualifier and @Primary for the same bean.

Use @Qualifier to inject specific bean otherwise Spring injects bean by default which is annotated with
@Primary
Let us create an interface University,

University.java

package com.easy;

public interface University {

public String display();

}
Now this university is implemented by couple of services, Alpha University and
Beta University
AlphaUniversity.java

package com.easy.service;

import com.easy.University;
import org.springframework.stereotype.Service;

@Service
public class AlphaUniversity implements University
{

@Override
public String display() {

return "This is a message from Alpha


University";

}
BetaUniversity

package com.easy.service;

import com.easy.University;
import org.springframework.stereotype.Service;

@Service
public class BetaUniversity implements University {

@Override
public String display() {

return "This is a message from Beta University";

}
Now let us have a controller,

UniversityController.java

package com.easy.controller;

import com.easy.University;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UniversityController {

@Autowired
private University university;

@GetMapping ("/university")
public String getUniversity() {

return university.display();

}
Now when we call “/univeristy” API which dependency will be actually called?

will it be Alpha University or Beta University?


Spring boot has considered BetaUniversity as a preferred bean when University is Autowired.

Now let us use @Qualifier annotation to differentiate beans,


Which is of higher priority @Primary or @Qualifier?

@Qualifier has higher priority than @Primary annotation.

In the above example we have used both @Primary and @Qualifier together – Qualifier has taken
higher priority than @Primary.

Can we declare both @Primary and @Qualifier together?

Yes, Both annotations can be used together but only one can be executed at a time. (Qualifier first, if
qualifier not present it will execute primary)
Spring Boot Framework

Day 14
How to Use Profiles in Spring
Boot?
What Are Profiles?
Every enterprise application has many environments, like:

Dev | Test | Acceptance | Production

Each environment needs its own specific settings. For example, in DEV, we don't need to check database
consistency all the time.

But in Test and Acceptance, we do need to check it. These environments have specific configurations
called Profiles.
How to Use Profiles in Spring Boot?

Video link : https://youtu.be/P4GPBpLhOug


Spring Boot Framework

Day 15
One-to-One Uni-directional
Mapping in Spring Boot
One-to-One Uni-directional Mapping

Table 1 Table 2

EmpI EmpNa TaskId TaskId Task


d me 7 Login issues
1 Naveen 8
8 Registration issues
2 Hussain 7
In JPA (Java Persistence API), a one-to-one unidirectional mapping means that there is a relationship
between two entities.

Where one entity has a reference to another entity, but the reverse is not true.

This is a unidirectional relationship because only one entity has knowledge of the other entity, and there is
no backward reference.

Example :

Let's consider an example with two entities: Employee and Task.

Employee has one Task reference task id, but the Task does not have a reference back to the Employee.
In JPA, the @GeneratedValue annotation is used to specify the primary key generation strategy for the @Id
field.

The strategy element of the @GeneratedValue annotation determines how the primary key values are
generated

The different generation strategies available in JPA:

@GeneratedValue(strategy = GenerationType.AUTO)

@GeneratedValue(strategy = GenerationType.IDENTITY)

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_seq")


@SequenceGenerator(name = "person_seq", sequenceName = "person_sequence", allocationSize = 1)

@GeneratedValue(strategy = GenerationType.TABLE, generator = "person_table_gen")


@TableGenerator(name = "person_table_gen", table = "id_gen", pkColumnName = "gen_name", valueColumnName =
"gen_value", pkColumnValue = "person_id", allocationSize = 1)
GenerationType.AUTO

Description: The persistence provider (e.g., Hibernate) will automatically choose the generation strategy
based on the underlying database.

Use Case: When you want the provider to decide the best generation strategy for the database.
GenerationType.IDENTITY

Description: The database generates the primary key values using an auto-increment column or a similar
mechanism.

Use Case: Suitable for databases that support auto-increment fields (e.g., MySQL, PostgreSQL).
GenerationType.SEQUENCE

Description: Uses a database sequence object to generate primary key values.


A sequence is a database object that generates a sequence of unique values.

Use Case: Suitable for databases that support sequence objects (e.g., Oracle, PostgreSQL).
GenerationType.TABLE

Description: Uses a database table to store and generate primary key values.

Use Case: Ideal for databases that do not support sequences or auto-increment columns.
It is more compatible across different databases.
Video link : https://youtu.be/JJwTNUPDSYE
The cascade attribute in the @OneToOne (or other relationship) annotation in JPA specifies the operations
that should be automatically propagated from the parent entity to the associated child entity.

Cascade Types :

Here are the different cascade types available in JPA:

CascadeType.PERSIST: When the parent entity is persisted, the related entity is also persisted.

CascadeType.MERGE: When the parent entity is merged, the related entity is also merged.

CascadeType.REMOVE: When the parent entity is removed, the related entity is also removed.

CascadeType.REFRESH: When the parent entity is refreshed, the related entity is also refreshed.

CascadeType.DETACH: When the parent entity is detached, the related entity is also detached.

CascadeType.ALL: All the above operations are cascaded to the related entity.
Spring Boot Framework

Day 16
One-to-One Bi-directional
Mapping in Spring Boot
One-to-One Bi-directional Mapping

Emp Table Task Table


EmpI EmpNa TaskId TaskId Task
d me
7 Login issues
1 Naveen 8
8 Registration issues
2 Hussain 7

Emp-Task
Table
EmpId TaskId
1 8
2 7
Video link : https://youtu.be/5ZZtdKghuiM
Spring Boot Framework

Day 17
One-to-Many Uni-
directional
Mapping in Spring Boot
One-to-Many Mapping

Emp Table Task Table

TaskId TaskName EmpId


EmpId EmpName
1 UI related issues 1
1 Saddam
Hussain 2 Login related issues 1
2 Naveen 3 Registration related 1
issues
4 Deployment issues 2
5 Infrastructure issues 2
Video link : https://youtu.be/irbKoEK5Gd0
Spring Boot Framework

Day 18
Many-to-One Bi-
directional

Mapping in Spring Boot


Many-To-One Bi-directional Mapping
Video link : https://youtu.be/dO9una6QqvY
Spring Boot Framework

Day 19
Many-to-Many Uni-
directional

Mapping in Spring Boot


Customer Table Item Table
Customer_Name Item_Id Items
Customer 2 Mobile
_Id
3 Laptop
1 Saddam Hussain
5 Earphones
4 Naveen
7 Mouse
6 Sagar
8 Headset

Customer Item Table


Customer_Id Item_Id

1 2
1 3
4 5
6 7
6 8
Video link : https://youtu.be/7AA7-h7oLlM
Spring Boot Framework

Day 20
Many-to-Many Bi-
directional

Mapping in Spring Boot


Video link : https://youtu.be/sus8Z7Nha7c
Spring Boot Framework

Day 21
Project Deployment Using Tomcat Server
Setting up a Spring Boot Application

Create a Spring Boot WAR

Deploy the WAR to Tomcat


Setting up a Spring Boot Application
Create a Spring Boot WAR

Extends the SpringBootServletInitializer class in the main class.

Marked the embedded servlet container as provided.

Override the Configure method.

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(SpringBootWarDeploymentExampleApplication.class);
}
Update packaging JAR to WAR

Modify the final WAR file name by using the <finalName> tag to avoid including the version numbers.

We have created a WAR file with the name web-services.

<finalName>web-services</finalName>
Create a WAR file by using the following steps:

Right-click on the project -> Run As -> 5 Maven Build


When the WAR file successfully created, it shows the WAR file path and a message BUILD SUCCESS in the
console, as shown in the following figure.
Copy the path and access the target folder of the application.

We found the WAR file inside the target folder with the same name as we have specified in the pom.xml file.
Deploy the WAR file to Tomcat

To deploy the WAR file, follow the steps below:


Download and install the Apache Tomcat Server, if not installed.

Copy the WAR file (web-services.war) and paste it inside the webapps folder of the Tomcat. In our case, the
location of the webapps folder is:
Now open the Command Prompt and type the following commands:

C:\Cd Program Files\Apache Software Foundation\Tomcat 8.5\bin


C:\Cd Program Files\Apache Software Foundation\Tomcat 8.5\bin>startup
Open the browser and invoke the URL http://localhost:8080/web-services/hello.

It returns the message

You might also like