0% found this document useful (0 votes)
24 views8 pages

8 Springboot Shortq

Uploaded by

prahallad Jena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views8 pages

8 Springboot Shortq

Uploaded by

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

springbo

otSpring Boot
[1.] What is Spring Boot?
o Spring Boot is an extension of the Spring Framework that simplifies the creation
the process of application , by providing defaults and auto-configuration.
2. What are the advantages of using Spring Boot?
o Rapid application development
o Simplified configuration
o Reduced boilerplate code
o Embedded servers like Tomcat or Jetty
o Easy integration with Spring ecosystem
3. What is the Spring Boot Starter?
o A Spring Boot Starter is a of special dependency jar it provide main jar ,it’s sub
jar and relevant jar and manage auto-configuration activitity and descriptors that
you can include in your project to get started with various Spring technologies
quickly.
4. What is an embedded server in Spring Boot?
o An embedded server means that the server (like Tomcat, Jetty, or Undertow) is
packaged within the application, eliminating the need for external server
installations.
5. What is Spring Boot Actuator?
o Spring Boot Actuator provides production-ready features such as monitoring and
management over REST endpoints.

o Spring Boot Actuator is a set of built-in tools and features that help monitor and
manage Spring Boot applications, providing endpoints for metrics, health checks,
and other operational information.
6. What is Spring Initializr?
Spring Initializr is a web-based tool provided by Spring to bootstrap a new Spring Boot
project with necessary dependencies.
 Spring Initializr is a web-based tool provided by the Spring Framework that
simplifies the process of creating a new Spring Boot project. It offers a user-friendly interface
where you can specify the project settings, dependencies, and other configurations to generate a
fully-functional Spring Boot application.
7. What is auto-configuration in Spring Boot?
o Auto-configuration is a feature in Spring Boot that automatically configures
Spring application based on the included dependencies and applied settings,
reducing the need for manual configuration.
o When you create a Spring Boot application, auto-configuration is automatically
enabled , the @SpringBootApplication annotation. This annotation is equivalent
to using @Configuration, @EnableAutoConfiguration, and @ComponentScan.
8. How do you create a Spring Boot application?
o You can create a Spring Boot application by using Spring Initializr, adding
dependencies to your pom.xml or build.gradle, and writing the
@SpringBootApplication annotated main class.
9. What is the purpose of the application.properties file in Spring Boot?
o The application.properties file is used to define application configuration
properties, such as server port, database connection settings, and other
customizable parameters.

o
10.How can you run a Spring Boot application?
 You can run a Spring Boot application by executing the main method in the main class
annotated with @SpringBootApplication or using the command mvn spring-
boot:run or gradle bootRun.

11.what is spring bean ?


A Spring Bean is an object that is instantiated, configured, and managed by the Spring IoC container.
These beans are created based on configuration metadata (like XML configuration, Java annotations, or
Java-based configuration) that tells the container how to instantiate, configure, and assemble the
objects.

12.How does Spring Boot handle dependency management?

 Spring Boot handles dependency management through its use of the Maven or Gradle build tools,
which manage dependencies and ensure compatibility with Spring Boot versions.

13.What is the role of the @SpringBootApplication annotation?

The @SpringBootApplication annotation is a convenience annotation that combines


@Configuration, @EnableAutoConfiguration, and @ComponentScan annotations, making it
easier to set up a Spring Boot application.

14. What is the purpose of @EnableAutoConfiguration annotation in Spring Boot?

 The @EnableAutoConfiguration annotation tells Spring Boot to automatically configure your


application based on the dependencies we have added in the classpath.

15.what is ioc container (Inversion of Control)

An IoC (Inversion of Control) container in Spring Boot is a core component that manages the
creation, configuration, and lifecycle of application components, It uses dependency injection to
automatically handle dependencies between beans, promoting loose coupling and making the
application easier to manage and test.

16.What role does the @Component annotation play in Spring Boot?


 The @Component annotation is used to mark a class as a Spring bean, making it eligible for
component scanning and inclusion in the IoC container.

17. How does the @Autowired annotation relate to the IoC container?

The @Autowired annotation is used to automatically inject dependencies into a bean, leveraging the
IoC container to resolve and provide the necessary dependencies.

What is the BeanFactory in Spring?

The BeanFactory is the root interface for accessing the Spring IoC container and managing beans. It
provides the basic functionality for dependency injection.

18.What is the difference between ApplicationContext and BeanFactory in Spring?


ApplicationContext is a more advanced and feature-rich container compared to BeanFactory.
It provides additional functionality such as event propagation, declarative mechanisms to create a bean,
and various enterprise-specific capabilities.

Eager vs. Lazy Loading

 BeanFactory: Loads beans lazily (only when needed).


 ApplicationContext: Loads all beans eagerly at startup.

Definition

 BeanFactory: The basic container in Spring for managing beans.


 ApplicationContext: A more advanced and feature-rich container that extends BeanFactory.

Event Handling

 BeanFactory: Does not support event propagation.


 ApplicationContext: Supports event handling through ApplicationEventPublisher

Usage Recommendation

 BeanFactory: Suitable for lightweight applications with limited features.


 ApplicationContext: Recommended for enterprise-level applications due to its advanced
features.

19.What does @Configuration annotation do in Spring Boot?

 The @Configuration annotation indicates that a class declares one or more @Bean methods and
can be processed by the Spring IoC container to generate bean definitions.
20.How do you define a bean in Spring Boot?

You can define a bean in Spring Boot using the @Bean annotation within a class annotated with
@Configuration.

21.How can you customize the bean initialization logic in Spring Boot?

You can customize the bean initialization logic by defining an @PostConstruct method in your bean
class or by implementing the InitializingBean interface.

22. What is the difference between @Service and @Repository annotations in Spring Boot?

The @Service annotation is used to indicate a service layer bean, while the @Repository
annotation is used to indicate a data access layer bean and also enables exception translation in data
access logic.

23. How do you create a custom scope in Spring Boot?

 You can create a custom scope in Spring Boot by implementing the Scope interface and registering it
with the ConfigurableBeanFactory

26.What is the purpose of the @Qualifier annotation?

 The @Qualifier annotation is used to specify which bean should be injected when there are
multiple beans of the same type, providing more control over dependency injection.

27. How does Spring Boot handle bean initialization order?

 Spring Boot handles bean initialization order using the @Order annotation or by implementing the
Ordered interface, allowing you to specify the order in which beans are initialized.

28. What is the difference between @Bean and @Component annotations?

 The @Bean annotation is used to define a bean within a @Configuration class, while the
@Component annotation is used to mark a class as a Spring-managed bean, making it eligible for
component scanning.

29. How do you define a prototype-scoped bean in Spring Boot?

You can define a prototype-scoped bean by using the @Scope("prototype") annotation on the bean
definition or the class.

30. What is the role of the @Primary annotation in Spring Boot?


 The @Primary annotation is used to indicate that a bean should be given preference when multiple
beans of the same type are present in the IoC container, thus resolving conflicts during dependency
injection.

31.How do you define a singleton bean in Spring Boot?

 By default, all beans in Spring Boot are singleton-scoped. You can explicitly define a singleton bean by
using the @Scope("singleton") annotation, though it is not necessary since it's the default scope.

32.What is the purpose of the @Lazy annotation?

 The @Lazy annotation is used to indicate that a bean should be lazily initialized, meaning it will be
created only when it is first requested rather than at startup.

33.How can you inject properties from an external configuration file into a Spring Boot bean?

You can inject properties from an external configuration file into a Spring Boot bean using the @Value
annotation to read specific properties or by using the @ConfigurationProperties annotation to
bind a group of properties to a bean.

34.How do you enable component scanning in a Spring Boot application?

Component scanning is enabled by default in a Spring Boot application with the


@SpringBootApplication annotation, which implicitly includes the @ComponentScan annotation.

35.What is the role of the ApplicationContext interface in Spring Boot?

 The ApplicationContext interface provides the central interface to the Spring IoC container,
offering features such as bean lifecycle management, event propagation, and resource loading.

36.What is bulk injection? How can we do

When we inject large volume of data to spring bean properties by using @ConfigurationProperties
on the top of class is called bulk injection

->it dynamically inject all properties, no need to place separately like @value

37.What is single value injection or @Value?

The @Value annotation in Spring Framework is used to inject single values into fields in a Spring-
managed bean. It can be used for injecting primitive types, Strings, and even properties from external
sources such as properties files or environment variables.
38.what is data source in springboot?

 a DataSource is still a factory for connections to the actual data source, like a database

Hickari dataSource is always good to use it gives great performance ,and in springboot it coming by
default

1.Tomcat cp

2.hickari

3.apache dbcp2

39.How can we add other data sources in spring boot?

Add our choice jdbc connection pool dependency /jar in our classpath

40.what is jdbc connectionpool ?


A JDBC connection pool is a method that manages and reuses database connections. Instead
of creating a new connection each time, it keeps a pool of connections ready to be used, reducing
the time and resources needed for frequent database access.
41.How can we specify new dataSource classname in application,properties file ?

By using Spring.datasource.type=com.mchange.v2.c3p0.Combopooleddatasource

42.How to specify min pool size and max pool and other additional properties while working with
HikariCp jdbc con pool?

spring .datasource.hikari.maximum-pool-size = 100

spring.datasource .minimum-idle = 10

42.How to configure custom perpoties file in springboot app?

@propertiesSource

spring.config.import

43.what is difference between @value and @configurationperpoties?


@Value

 Purpose: Used to inject single property values into Spring beans.


 Usage: Typically used for basic, individual property injection.
 Scope: Limited to the specific field it is applied to.
 Configuration: Properties are specified in application.properties or
application.yml.

@ConfigurationProperties

 Purpose: Used to bind a group of related properties to a Java bean.


 Usage: Ideal for complex or hierarchical configurations.
 Scope: Applies to the entire class and its properties.
 Configuration: Properties are specified in application.properties or
application.yml with a prefix.

44.what is Runner in springboot?

Runner is spring bean in springBoot ,it contain single execution logic in run() method

it Automatically called by sprigboot as part of application startup process ,that is started by

SpringApplication.run() method

 that is used to execute code after the application has started. There are two main types of
runners:
1. CommandLineRunner: This is a functional interface with a single method
run(String... args). It is used to run code after the Spring Boot application has
started, and it can accept command-line arguments.
2. ApplicationRunner: This is similar to CommandLineRunner, but it uses the
ApplicationArguments interface, which provides more advanced argument parsing
capabilities.
3. Both CommandLineRunner and ApplicationRunner are useful for executing logic
immediately after the application context has been initialized.
The springboot app recognizes the spring bean class as a runner class by seeing XxxRunner interface

45.what is Adventages of autoCongiguration?

simplyfie :: Auto-configuration simplifies the setup process by automatically configuring systems and
applications based on predefined rules and conditions.

TimeSaving:: By automating the configuration process, developers and administrators save time

felixibility:: Auto-configuration can adapt to different environments and requirements by


using condition-based rules.
46. How does dependency injection , lookup used in real time ?

Dependency Injection (DI) is a design pattern where an object's dependencies are assign in another
dependency by using @autowired . This helps in creating loosely coupled, maintainable, and testable
code.

A lookup in software development is a technique used to find and retrieve a dependency or resource
at runtime, typically from a central registry or service locator.

You might also like