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 3 of 3)

  1. Why does placing @Valid on a request body parameter in a Spring Boot controller method change runtime behavior?Multiple choiceMedium
  2. How does using a DTO prevent exposing sensitive data in a REST API?Multiple choiceMedium
  3. Why does self-invocation of a method with @Transactional annotation not work as expected in Spring?Multiple choiceHard
  4. Why does @Autowired in Spring matter in this design?Multiple choiceEasy
  5. How would you explain a potential risk of using field injection instead of constructor injection in a Spring-managed transactional service in an interview?Multiple choiceHard
  6. Which annotation would you use to enable transaction management in a Spring Boot application?Multiple choiceEasy
  7. In a Spring Boot application, what is a potential risk of using self-invocation for a method annotated with @Transactional?Multiple choiceMedium
  8. What default scope does Spring assign to a bean if no specific scope is declared?Multiple choiceEasy
  9. Why does self-invocation of a method with a @Transactional annotation not work in a Spring application?Multiple choiceHard
  10. How would you explain a common issue when using Spring transactions with self-invocation, and how can you solve it in an interview?Multiple choiceHard
  11. Which Spring Boot annotation can be used to combine multiple other annotations commonly used in @Configuration classes?Multiple choiceMedium
  12. Why does the @Autowired annotation in Spring matter in this design?Multiple choiceEasy
  13. What challenge does transaction self-invocation pose in Spring, and how can it be addressed?Multiple choiceHard
  14. How can serialization boundaries help prevent data leaks in a Spring Boot application?Multiple choiceHard
  15. Which Spring annotation is used to automatically wire a bean into another?Multiple choiceEasy
  16. Which of the following is true about Spring's proxy-based transaction management?Multiple choiceEasy
  17. Why does a @RestController in a Spring Boot application matter in this design?Multiple choiceEasy
  18. In a typical Spring Boot application, where should transaction management be applied?Multiple choiceMedium
  19. Why do application properties and profiles matter in a production Spring Boot app?Multiple choiceMedium
  20. In a Spring Boot application, how can you programmatically activate a specific profile?Multiple choiceHard
  21. Which scope of a bean in Spring is the default in Java?Multiple choiceEasy
  22. How would you explain a potential issue with using a Prototype scoped bean in a Singleton bean in an interview?Multiple choiceEasy
  23. What does the @Bean annotation indicate in a Spring Boot application?Multiple choiceEasy
  24. Why might you choose prototype scope for a Spring bean in a multi-threaded environment?Multiple choiceMedium
  25. Why is it important to avoid exposing the password field in a User entity via a REST API?Multiple choiceMedium
  26. In Spring Boot, how can you exclude a specific auto-configuration class from being applied?Multiple choiceMedium
  27. How should a @Service layer method be structured in a Spring Boot application?Multiple choiceMedium
  28. In Spring Boot, what is the default scope of a bean?Multiple choiceEasy
  29. Which of the following is NOT a benefit of using Spring's Dependency Injection?Multiple choiceEasy
  30. How can you configure a Spring Boot application to reject invalid requests at the controller level?Multiple choiceHard
  31. In what scenario is it beneficial to use a Prototype scope bean over a Singleton in Spring Boot?Multiple choiceHard
  32. How can you resolve the issue of transaction self-invocation in Spring?Multiple choiceHard
  33. Which of the following is a key benefit of using constructor injection in Spring Boot?Multiple choiceMedium
  34. Why does a transaction-managed method invokes another method in the same class directly cause a problem in practice?Multiple choiceMedium
  35. How does constructor injection benefit a Spring Boot application?Multiple choiceEasy
  36. In a Spring Boot application, which layer should handle the conversion of HTTP requests to business operations?Multiple choiceEasy
  37. Which annotation should be used to indicate a class as a Spring Data Repository?Multiple choiceEasy
  38. How does Spring Boot differentiate between @Repository and @Service annotations?Multiple choiceMedium
  39. Which bean scope would you use in a Spring application to ensure a new bean instance is created for each HTTP request?Multiple choiceMedium
  40. In Spring Boot, what happens when a class is annotated with @Component?Multiple choiceEasy
  41. Why might a transaction not roll back even if a RuntimeException is thrown?Multiple choiceMedium
  42. How does Spring handle transactions when methods marked with @Transactional are called from different beans?Multiple choiceMedium
  43. Which of the following scopes is NOT a valid Spring bean scope?Multiple choiceMedium
  44. Why is it generally a bad practice to expose database entities directly in a Spring Boot API?Multiple choiceEasy