Skip to content
Sharp

Spring Core interview questions

Application Properties, Bean Scope, Controllers, Services, Repositories, DTOs and Entities, Inversion of Control (IoC), Persistence and Validation

144 questions with answers and explanations · 142 flashcards

Questions (page 1 of 3)

  1. Why do teams use Spring Profiles in a Spring Boot application in production code?Multiple choiceMedium
  2. In a Spring Boot application, what happens if a method annotated with @Transactional calls a private method also annotated with @Transactional?Multiple choiceHard
  3. Which layer should coordinate inventory checks, payment, and order persistence for a checkout request?Multiple choiceEasy
  4. What role do Entities typically play in a Spring Boot application?Multiple choiceEasy
  5. How can you externalize configuration in a Spring Boot application?Multiple choiceEasy
  6. Which issue might arise from using field injection in Spring Boot, particularly when managing dependencies?Multiple choiceHard
  7. In a Spring Boot application, what is the main purpose of the @ComponentScan annotation?Multiple choiceMedium
  8. What issue might arise if a method annotated with @Transactional calls another method within the same class also annotated with @Transactional?Multiple choiceMedium
  9. In Spring, what is the primary role of a dynamic proxy when using @Transactional?Multiple choiceEasy
  10. In a Spring Boot application, which scope would you use for a bean that should be instantiated once per HTTP request?Multiple choiceMedium
  11. How does the Spring container manage the lifecycle of a bean with prototype scope?Multiple choiceMedium
  12. In the context of Spring, what issue arises when a transaction-managed method calls another method in the same class?Multiple choiceHard
  13. Which of the following is a benefit of using constructor injection over field injection in Spring Boot?Multiple choiceHard
  14. How can Spring Boot applications be configured to use environment variables?Multiple choiceMedium
  15. Why does a @Repository in a Spring Boot application matter in this design?Multiple choiceMedium
  16. Which Spring feature allows for automatic dependency injection?Multiple choiceEasy
  17. Why can @Transactional fail when one method inside a bean calls another transactional method on the same bean?Multiple choiceMedium
  18. Why is input validation strongest at the controller boundary?Multiple choiceHard
  19. Which annotation would you use to ensure that a field in a Spring Boot controller method is not blank?Multiple choiceEasy
  20. Which Bean scope should be used for a component that needs to maintain user session data?Multiple choiceHard
  21. How can you specify a default value for a configuration property when using the @Value annotation in Spring?Multiple choiceMedium
  22. In a Spring Boot application, how can you inject a configuration property into a field using the @Value annotation?Multiple choiceEasy
  23. Why is constructor injection preferred over field injection in Spring?Multiple choiceMedium
  24. Which scope of a Spring Bean is the default in Java?Multiple choiceMedium
  25. How would you explain a potential risk of using instance variables in a singleton bean in a concurrent environment in an interview?Multiple choiceMedium
  26. In Spring Boot, which annotation is typically used to define a class that holds business logic?Multiple choiceEasy
  27. Which annotation is used in Spring to define a method as part of a transaction?Multiple choiceEasy
  28. In Spring Boot, how can you validate the fields of a request body in a REST controller?Multiple choiceMedium
  29. Which approach can help ensure thread safety when using singleton beans?Multiple choiceMedium
  30. Why do teams use constructor injection in a Spring Boot application in production code?Multiple choiceMedium
  31. Why is it advisable to move methods requiring transactions to separate Spring beans?Multiple choiceMedium
  32. In Spring Boot, which of the following is the correct way to inject a configuration property from application.properties?Multiple choiceEasy
  33. How can you address the issue of transaction self-invocation in Spring?Multiple choiceMedium
  34. Why is constructor injection generally preferred in Spring Boot over setter injection?Multiple choiceMedium
  35. Which Spring Boot feature helps in rejecting invalid data before it hits the service layer?Multiple choiceMedium
  36. Why is it dangerous to use stateful instance variables in a Singleton service?Multiple choiceHard
  37. What scope should be used for beans that need to maintain state specific to a user's session in a web application?Multiple choiceEasy
  38. Which of the following best describes constructor injection in Spring?Multiple choiceMedium
  39. Why would you choose to use Spring Profiles in a Spring Boot application?Multiple choiceMedium
  40. How does constructor injection benefit transaction management in Spring?Multiple choiceMedium
  41. Why do teams use an interface-based proxy for transaction management over a CGLIB proxy in production code?Multiple choiceHard
  42. How would you explain a potential issue when using CGLIB-based proxies for transaction management in Spring in an interview?Multiple choiceHard
  43. In which scenario is Prototype scope preferred over Singleton scope in a Spring application?Multiple choiceHard
  44. Which Spring bean scope would be appropriate for a service managing transactions in a web application?Multiple choiceMedium
  45. How can you ensure thread safety when using a singleton-scoped bean in Spring?Multiple choiceHard
  46. How would you explain a potential consequence of directly exposing JPA entities in a REST API in an interview?Multiple choiceMedium
  47. What does the @NotBlank annotation ensure in Java Bean Validation?Multiple choiceEasy
  48. In Spring Boot, which annotation would you use to ensure that a method parameter is not null?Multiple choiceEasy
  49. How does Spring Boot's auto-configuration decide which beans to create?Multiple choiceHard
  50. In Spring Boot, what is the default scope of a bean if no scope is explicitly defined?Multiple choiceEasy