Spring Interview Question
Spring Interview Question
1. Why will you choose Spring Boot over Spring Framework ?
2. What all spring boot starter you have used or what all module you have worked on ?
3. How will you run your Spring Boot application ?
4. What is the purpose of the @SpringBootApplication annotation in a Spring Boot application ?
5. can I directly use @EnableAutoConfiguration ,@ComponentScan & @Configuration annotation
in my main class , instead of using
@SpringBootApplication annotation , if yes will my application work as expected ?
6. What is Auto configuration in spring boot ?
7. How can you disable a specific auto-configuration class in Spring Boot ?
8. How can you customize the default configuration in Spring Boot ?
9. How Spring boot run() method works internally ?
10. What is Command line runner in spring boot ?
1. Can you explain the purpose of Stereotype annotations in the Spring Framework ?
2. How can you define bean in spring framework ?
3. What is dependency injection ?
4. How many ways we can perform dependency injection in spring or spring boot ?
5. where you would choose to use setter injection over constructor injection, and vice versa ?
6. Can you provide an example of a real-world use case where @PostConstruct is particularly
useful?
7. How can we dynamically load values in a Spring Boot application?
8. Can you explain the key differences between YML and properties files, and in what scenarios
you might prefer one format over the other?
9. What is the difference between yml & YAML ?
10. If I will configure same values in both properties then which value will be load in spring boot
OR Who will load first properties or yml file ?
11. How to load External Properties in Spring Boot ?
12. How to map or bind config properties to java Object ?
1. Have you worked on Restful webservices ? If yes What all HTTP methods have you used in
your project ?
2. How can you specify the HTTP method type for your REST endpoint?
3. Scenario : Can you design a rest endpoint , Assume that you have a Product database, and
your task is to create an API to filter a list of products by productType ?
4. Scenario : Design endpoints in a way that takes “productType” as input. If the user provides
this input, the endpoint should filter products based on the specified condition. If
“productType” is not provided, the endpoint should return all the products. ?
5. What is the difference between @PathVariable & @RequestParam ?
6. Why did you use @RestController why not @Controller ?
7. How can we deserialize a JSON request payload into an object within a Spring MVC controller ?
8. Can we perform update operation in POST http method if yes then why do we need Put
Mapping or put http method?
9. Can we pass Request Body in GET HTTP Method ?
10. How can we perform content negotiation (XML/JSON) in Rest endpoint ?
11. What all status code you have observed in your application ?
12. How can you customize the status code for your endpoint ?
13. How can you enable cross origin ?
14. How can you upload a file in spring ?
15. How do you maintain versioning for your REST API?
16. How will you document your rest API ?
17. How can you hide certain REST endpoints to prevent them from being exposed externally?
18. How will you consume restful API ?
1. How does your application interact with the database and which frameworks are you using?
2. Why is it important to configure a physical naming strategy?
3. What are the key benefits of using Spring Data JPA ?
4. What are the differences between Hibernate, JPA, and Spring Data JPA?
5. How can you connect multiple databases or data sources in a single application?
6. What are the different ways to define custom queries in Spring Data JPA ?
7. Can you provide example to find results based on some range
8. Ex 1 : Find list of employees whose age in between 30 lakh to 35 lakh
9. Ex 2 : find avg salary of employees in an organization
10. How will you define entity relationships or association mapping in Spring Data JPA?
11. (Use Case: Consider an e-commerce application where each customer can have multiple
orders. Here, a Customer entity can be associated with multiple Order entities.)
12. Is this possible to execute Join query in Spring Data JPA ? If yes, how can you add some
insights ?
13. How will you implement pagination & Sorting in Spring Data JPA ?
1. If you had to scale a Spring Boot application to handle high traffic, what strategies would you use?
2. Imagine Your application requires data from an external REST API to function. Describe how you
would use RestTemplate or WebClient to consume the REST API in your Spring Boot application.
3. Your Spring Boot backend needs to accept cross-origin requests from a specific frontend domain.
Explain how you would configure CORS policies in your application.
4. Your Spring Boot application is experiencing performance issues under high load. What are the
steps you would take to identify and address the performance?
5. Imagine you need to make a simple web application with Spring Boot that serves a static
homepage and a dynamic page displaying current server time. Discuss the project structure you
would use.
6. Your application behaves differently in development and production environments. How would
you use Spring profiles to manage these differences?
7. What strategies would you use to optimize the performance of a Spring Boot application?
8. Describe a scenario where a Spring Boot application needs to dynamically switch between
multiple data sources at runtime based on the request context.
9. Discuss how you would add a GraphQLAPI to an existing Spring Boot RESTful service.
10. Describe how you would secure sensitive data in a Spring Boot application that is accessed by
multiple users with different roles.
11. In an IoT application scenario, explain how a Spring Boot backend could be designed to efficiently
process and analyze real-time data streams from thousands of IoT devices.
12. Discuss the specific security challenges associated with using WebSocketsin a Spring Boot
application.
13. How would you implement efficient handling of large file uploads in a Spring Boot REST API,
ensuring that the system remains responsive and scalable?
14. How you would use Spring WebFluxto consume data from an external service in a non-blocking
manner and process this data reactively within your Spring Boot application.
15. Imagine you need to develop a REST API in a Spring Boot application that allows clients to manage
user data. Explain how you would structure your application.
16. Imagine you are designing a Spring Boot application that interfaces with multiple external APIs.
How would you handle API rate limits and failures?
17. You need to deploy a Spring Boot application to a cloud platform (e.g., AWS, Azure). What steps
would you take, and how would you configure the application properties for different
environments.
18. Explain how you would use application events in Spring Boot to notify different parts of your
application about significant activities.