Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Springbootnotes

Spring boot is a Java framework used to create microservices. It allows for rapid development through auto-configuration and embedded servers. Key benefits include minimal configuration, embedded servers, and increased productivity. Common components include auto-configuration, starters, and actuators for monitoring applications.

Uploaded by

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

Springbootnotes

Spring boot is a Java framework used to create microservices. It allows for rapid development through auto-configuration and embedded servers. Key benefits include minimal configuration, embedded servers, and increased productivity. Common components include auto-configuration, starters, and actuators for monitoring applications.

Uploaded by

shamitha
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

What is Spring boot?

Sprint boot is a Java-based spring framework used for Rapid Application Development
(to build stand-alone microservices). It has extra support of auto-configuration
and embedded application servers like tomcat, jetty, etc.

What are the advantages of using Spring Boot?


Creates stand-alone spring application with minimal configuration needed.
It has embedded tomcat, jetty which makes it just code and run the application.
Increases productivity and reduces development time.
We don’t need to write any XML configuration, only a few annotations are required
to do the configuration.

What are the Spring Boot key components?


Spring Boot auto-configuration.
Spring Boot CLI.
Spring Boot starter POMs.
Spring Boot Actuators.

Why Spring Boot over Spring?


Below are some key points which spring boot offers but spring doesn’t:
Starter POM.
Version Management.
Auto Configuration.
Component Scanning.
Embedded server.
InMemory DB.
Actuators

What is the starter dependency of the Spring boot module?


Spring boot provides numbers of starter dependency, here are the most commonly used
-
Data JPA starter.
Test Starter.
Security starter.
Web starter.
Mail starter.
Thymeleaf starter.

How does Spring Boot works?


Spring Boot automatically configures your application based on the dependencies you
have added to the project by using annotation. The entry point of the spring boot
application is the class that contains @SpringBootApplication annotation and the
main method.
Spring Boot automatically scans all the components included in the project by using
@ComponentScan annotation.
Start by creating a new Spring Boot project.
Add the necessary dependencies to your project.
Annotate the application with the appropriate annotations.
Run the application.

What does the @SpringBootApplication annotation do internally?


The @SpringBootApplication annotation is equivalent to using @Configuration,
@EnableAutoConfiguration, and @ComponentScan with their default attributes. Spring
Boot enables the developer to use a single annotation instead of using multiple.

How does a spring boot application get started?


Just like any other Java program, a Spring Boot application must have a main
method. This method serves as an entry point, which invokes the
SpringApplication#run method to bootstrap the application.
What are starter dependencies?
They are collection of all the dependencies which are needed to start a particular
functionality.
Like we need to import spring-boot-starter-web dependency for creating a web
application.

What is Spring Initializer?


Spring Initializer is a web application that helps you to create an initial spring
boot project structure and provides a maven or gradle file to build your code. It
solves the problem of setting up a framework when you are starting a project from
scratch.

What is Spring Boot CLI and what are its benefits?


Spring Boot CLI is a command-line interface that allows you to create a spring-
based java application using Groovy.
Example: You don’t need to create getter and setter method or access modifier,
return statement. If you use the JDBC template, it automatically loads for you.

What are the most common Spring Boot CLI commands?


-run, -test, -grap, -jar, -war, -install, -uninstall, --init, -shell, -help.

What Are the Basic Annotations that Spring Boot Offers?


@SpringBootApplication:This is the main annotation used to bootstrap a Spring Boot
application. It combines three annotations: @Configuration,
@EnableAutoConfiguration, and @ComponentScan. It is typically placed on the main
class of the application.used to denote the main class of a Boot Application.
@Configuration: This annotation is used to indicate that a class contains
configuration methods for the application context. It is typically used in
combination with @Bean annotations to define beans and their dependencies.
@Component: This annotation is the most generic annotation for any Spring-managed
component. It is used to mark a class as a Spring bean that will be managed by the
Spring container.
@RestController: This annotation is used to define a RESTful web service
controller. It is a specialized version of the @Controller annotation that includes
the @ResponseBody annotation by default.
@RequestMapping: This annotation is used to map HTTP requests to a specific method
in a controller. It can be applied at the class level to define a base URL for all
methods in the class, or at the method level to specify a specific URL mapping.

What is Spring Boot dependency management?


Spring Boot dependency management is used to manage dependencies and configuration
automatically without you specifying the version for any of that dependencies.

Can we create a non-web application in Spring Boot?


Yes, we can create a non-web application by removing the web dependencies from the
classpath, we can create applications like Microservices, Console applications, and
batch applications.

Is it possible to change the port of the embedded Tomcat server in Spring Boot?
Yes, it is possible to change the port of the embedded Tomcat server in a Spring
Boot application.
The simple way is to set the server. port property in your application’s
application.properties file. For example, to set the port to 8081, add the
following property to the application.properties file:

What is the default port of Tomcat in spring boot?


The default port of the embedded Tomcat server in Spring Boot is 8080. We can
change the default port by setting the server.port property in your application’s
application.properties file.

Can we override or replace the Embedded tomcat server in Spring Boot?


Yes, we can replace the Embedded Tomcat server with any server by using the Starter
dependency in the pom.xml file. Like you can use spring-boot-starter-jetty as a
dependency for using a jetty server in your project.

Can we disable the default web server in the Spring Boot application?
Yes, we can disable the default web server in the Spring Boot application. To do
this, we need to set the server.port property to “-1” in the application’s
application.properties file.

How to disable a specific auto-configuration class?


To disable a specific auto-configuration class in a Spring Boot application, we can
use the @EnableAutoConfiguration annotation with the “exclude” attribute.

Describe the flow of HTTPS requests through the Spring Boot application.
First client makes an HTTP request (GET, POST, PUT, DELETE) to the browser.
After that the request will go to the controller, where all the requests will be
mapped and handled.
After this in Service layer, all the business logic will be performed. It performs
the business logic on the data that is mapped to JPA (Java Persistence API) using
model classes.
In repository layer, all the CRUD operations are being done for the REST APIs.
A JSP page is returned to the end users if no errors are there.

Explain @RestController annotation in Spring boot?


It is a combination of @Controller and @ResponseBody, used for creating a restful
controller. It converts the response to JSON or XML.

What is the difference between @RestController and @Controller in Spring Boot?


@Controller Map of the model object to view or template and make it human
readable,It marks a class as a controller class,Used for Web applications,Used with
@RequestMapping annotation to map HTTP requests with methods.
@RestController It combines two annotations i.e. @Controller and @ResponseBody,
Used for RESTful APIs,Used to handle requests like GET, PUT, POST, and DELETE.
simply returns the object and object data is directly written in HTTP response as
JSON or XML.

What is the difference between RequestMapping and GetMapping?


Handles various types of HTTP requests (GET, POST, etc.)
@RequestMapping(value = “/example”, method = RequestMethod.GET)
Specifically handles HTTP GET requests.
@GetMapping(“/example”)

What is the use of Profiles in spring boot?


While developing the application we deal with multiple environments such as dev,
QA, Prod, and each environment requires a different configuration. For eg., we
might be using an embedded H2 database for dev but for prod, we might have
proprietary Oracle or DB2. Even if DBMS is the same across the environment, the
URLs will be different.
To make this easy and clean, Spring has the provision of Profiles to keep the
separate configuration of environments.

What is Spring Actuator? What are its advantages?


An actuator is an additional feature of Spring that helps you to monitor and manage
your application when you push it to production. These actuators include auditing,
health, CPU usage, HTTP hits, and metric gathering, and many more that are
automatically applied to your application.
How to enable Actuator in Spring boot application?
To enable the spring actuator feature, we need to add the dependency of “spring-
boot-starter-actuator” in pom.xml.

What are the actuator-provided endpoints used for monitoring the Spring boot
application?
Actuators provide below pre-defined endpoints to monitor our application -

Health
Info
Beans
Mappings
Configprops
Httptrace
Heapdump
Threaddump
Shutdown

How to get the list of all the beans in your Spring boot application?
Spring Boot actuator “/Beans” is used to get the list of all the spring beans in
your application.

How to check the environment properties in your Spring boot application?


Spring Boot actuator “/env” returns the list of all the environment properties of
running the spring boot application.

Where do we define properties in the Spring Boot application?


You can define both application and Spring boot-related properties into a file
called application.properties

What is dependency Injection?


The process of injecting dependent bean objects into target bean objects is called
dependency injection.

Setter Injection: The IOC container will inject the dependent bean object into the
target bean object by calling the setter method.
Constructor Injection: The IOC container will inject the dependent bean object into
the target bean object by calling the target bean constructor.
Field Injection: The IOC container will inject the dependent bean object into the
target bean object by Reflection API.

What is an IOC container?


IoC Container is a framework for implementing automatic dependency injection. It
manages object creation and its life-time and also injects dependencies into the
class.

How to enable Actuator in the Spring boot application?


Below are the steps to enable actuator in Spring Boot Application:
Add Actuator dependency.
Enable endpoints in application.properties.
Run your Spring Boot app.

What are the @RequestMapping and @RestController annotations in Spring Boot used
for?
@RequestMapping: @RequestMapping is used to map HTTP requests to handler methods in
your controller classes. It can be used at the class level and method level. It
supports mapping by:
HTTP method – GET, POST, PUT, DELETE
URL path
URL parameters
Request headers
@RestController: @RestController is a convenience annotation that combines
@Controller and @ResponseBody. It indicates a controller where every method returns
a domain object instead of a view.
@RestController = @Controller + @ResponseBody

What is Spring Bean?


An object that is managed by the Spring IoC container is referred to as a spring
bean. A Spring bean can be any Java object.

What is the purpose of the @Bean annotation?


What is the purpose of the @Autowired annotation?
What is the purpose of the @Value annotation?
What is the purpose of the @Profile annotation?
How to access actuator endpoints in Spring Boot?

What is thyme leaf?


Thyme leaf is a popular templating engine used in Spring Boot applications for
building dynamic web pages. Moreover, it is humanly readable and developers can use
it to create templates that can be rendered in HTML

How do you connect Spring Boot to the database using JPA?


How to connect the Spring Boot application to a database using JDBC?

You might also like