Top 20 Spring Boot Interview Questions for Experienced Developers
Preparing for a Spring Boot interview? Whether you work in product-based or service companies, these 20 carefully crafted questions are based on real-world scenarios and are ideal for Java backend developers with 2+ years of hands-on Spring Boot experience.
1. What is Spring Boot and how is it different from Spring?
Answer: Spring Boot simplifies Spring application setup with auto-configuration, embedded servers, and minimal XML. It is built on top of Spring and makes development faster and easier.
2. What are the key advantages of Spring Boot?
Answer:
- Auto Configuration
- Embedded servers like Tomcat/Jetty
- No boilerplate XML
- Production-ready tools via Actuator
- Faster deployment lifecycle
3. What is @SpringBootApplication
?
Answer: It combines @Configuration
, @EnableAutoConfiguration
, and @ComponentScan
. It marks the main class of your Spring Boot app.
4. How does Spring Boot's auto-configuration work?
Answer: It uses @EnableAutoConfiguration
and classpath analysis to configure beans automatically, based on dependencies using conditional annotations.
5. What is the role of application.properties
or .yml
?
Answer: They hold application configuration like port, DB URL, logging level, and profile setup.
6. Difference between @Component
, @Service
, and @Repository
?
Answer:
@Component
– Generic stereotype for a Spring-managed component.@Service
– Marks business logic layer.@Repository
– Used in DAO layer with built-in exception translation.
7. How is dependency injection done in Spring Boot?
Answer: Using @Autowired
or constructor injection. Constructor injection is preferred for better testability and immutability.
8. What are Spring Profiles?
Answer: They allow different configurations for different environments like dev
, test
, and prod
. You activate them via spring.profiles.active
.
9. What is Spring Boot Actuator?
Answer: It provides endpoints to monitor application health, metrics, info, and more.
10. How do you configure a database connection in Spring Boot?
Answer: Use properties like spring.datasource.url
, username
, and password
in application.properties
. Spring Boot auto-configures DataSource and JPA.
11. What is @RestController
?
Answer: It's a shortcut for @Controller
+ @ResponseBody
, used to create RESTful web services.
12. Difference between @RequestParam
and @PathVariable
?
Answer:
@RequestParam
– used for query params (e.g.,/api?id=1
)@PathVariable
– used for URI segments (e.g.,/api/1
)
13. What is Spring Data JPA?
Answer: It simplifies database access using interfaces like JpaRepository
. No need to write boilerplate CRUD queries.
14. How do you handle exceptions in Spring Boot REST APIs?
Answer: Use @ControllerAdvice
with @ExceptionHandler
to handle exceptions globally and return custom JSON responses.
15. What embedded servers does Spring Boot support?
Answer: Tomcat (default), Jetty, and Undertow. You can switch by changing dependencies.
16. How do you secure REST APIs in Spring Boot?
Answer: Using Spring Security with basic auth, JWT tokens, role-based access control, and endpoint whitelisting.
17. What is @Transactional
?
Answer: It manages transactions automatically. If a method fails, it rolls back DB changes.
18. How do you write unit and integration tests?
Answer: Use @SpringBootTest
, @MockBean
, JUnit 5, and Mockito for mocking. Use @WebMvcTest
for controller tests.
19. Difference between Spring Boot and Spring MVC?
Answer: Spring Boot includes Spring MVC, but adds auto-configuration, embedded servers, and faster bootstrapping. Spring MVC requires manual configuration.
20. How do you monitor Spring Boot applications?
Answer:
- Actuator endpoints like
/health
,/metrics
- Integration with Prometheus + Grafana
- Spring Boot Admin
- ELK stack (Elasticsearch, Logstash, Kibana)
🔥 Final Tips:
- Always explain based on your real project experience
- Mention tools like Postman, Jenkins, Git if used
- Be clear on your role in the implementation
📅 Last Updated: 20 May 2025
📌 Bookmark InterviewYatra.com for the best Java + Spring Boot interview prep.
0 Comments