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

  1. Why might Spring transactions not work as expected when invoking a transactional method within the same class?Multiple choiceHard
  2. Which mental model is most useful for understanding the Spring Application Context?Multiple choiceEasy
  3. Why do teams use Spring’s dynamic proxy for @Transactional in production code?Multiple choiceEasy
  4. Why might you choose to use an interface-based proxy over a CGLIB-based proxy in Spring?Multiple choiceMedium
  5. Why might using field injection in Spring components be discouraged in favor of constructor injection?Multiple choiceHard
  6. Why might constructor injection be preferred over setter injection in Spring?Multiple choiceHard
  7. Which Spring annotation would you use to indicate a boundary for serialization in a DTO?Multiple choiceMedium
  8. Why do teams use a Proxy object in Spring's AOP in production code?Multiple choiceMedium
  9. Which of the following is a valid way to declare a Prototype scoped bean in a Spring configuration class?Multiple choiceMedium
  10. Which Spring Boot annotation is used to indicate that a method parameter should be bound to a web request parameter?Multiple choiceEasy
  11. If you want a transaction to rollback on a checked exception, what must you do?Multiple choiceMedium
  12. In Spring, what is the main drawback of using a Prototype bean within a Singleton bean without proper management?Multiple choiceHard
  13. Why is returning a JPA entity directly from a controller risky?Multiple choiceHard
  14. In a Spring Boot application, where would you typically configure transaction management settings like rollback rules?Multiple choiceMedium
  15. Why does the @Configuration annotation in a Spring Boot application matter in practice?Multiple choiceMedium
  16. How can you configure a Spring Boot application to use different properties for development and production environments?Multiple choiceMedium
  17. What benefit does Spring Boot’s auto-configuration provide over traditional Spring configuration?Multiple choiceMedium
  18. When using constructor injection, what happens if a required dependency is missing?Multiple choiceHard
  19. How can you specify a default value for a property in Spring when using the @Value annotation?Multiple choiceEasy
  20. Which annotation would you use to ensure a field is greater than zero?Multiple choiceMedium
  21. How can you declare a custom validation constraint in Spring?Multiple choiceMedium
  22. What happens if a Spring Boot application has no application.properties or application.yml file?Multiple choiceHard
  23. Which scope of beans in a Spring application context is the default in Java?Multiple choiceMedium
  24. Which bean scope should you use for a Spring bean that needs to maintain state across a web session?Multiple choiceMedium
  25. Which Spring Bean scope is most appropriate for a stateful object in a web application?Multiple choiceMedium
  26. What happens if a method in a @Service class invokes another method in the same class that is annotated with @Transactional?Multiple choiceHard
  27. How can you ensure that a Spring Boot service only processes valid data from a controller method?Multiple choiceMedium
  28. How can you ensure thread safety when using a Singleton bean?Multiple choiceMedium
  29. How would you explain a potential consequence of self-invocation in a Spring bean with @Transactional methods in an interview?Multiple choiceHard
  30. Why do teams use DTOs in a Spring Boot application in production code?Multiple choiceMedium
  31. What happens if a method with @Transactional annotation calls another method in the same class that is also annotated with @Transactional?Multiple choiceMedium
  32. Why might constructor injection be preferred over field injection in Spring?Multiple choiceMedium
  33. Which annotation is commonly used to indicate that a class is a DTO in Spring Boot?Multiple choiceMedium
  34. How does using DTOs in a Spring application help maintain API versioning?Multiple choiceHard
  35. In a Spring Boot application, why might self-invocation of a method annotated with @Transactional fail to apply the transaction?Multiple choiceHard
  36. In a Spring Boot e-commerce application, why is constructor injection preferred over field injection for a @Service class?Multiple choiceMedium
  37. Which of the following is a potential drawback of using field injection in Spring?Multiple choiceHard
  38. Which annotation is used to apply validation constraints to a Java Bean?Multiple choiceEasy
  39. What happens if a method marked with @Transactional calls another method within the same class that is also marked with @Transactional?Multiple choiceHard
  40. How can you ensure that two methods within the same class, both requiring transactions, are properly managed by Spring's transaction management?Multiple choiceHard
  41. Which Spring annotation is used to define a method that should be executed after a bean's properties have been set?Multiple choiceMedium
  42. What happens when a Singleton bean is injected with a Prototype bean?Multiple choiceMedium
  43. What scope should be used for a Spring Bean that needs to be instantiated for each HTTP request?Multiple choiceEasy
  44. Why might you choose to use a @Configuration class in a Spring Boot application?Multiple choiceMedium
  45. Which annotation is used to define a bean's scope in Spring?Multiple choiceEasy
  46. Which command is used to run a compiled Spring Boot JAR file?Multiple choiceMedium
  47. In Spring Boot, why is it recommended to use DTOs when communicating between the service layer and controllers?Multiple choiceEasy
  48. Which Spring bean scope is least suitable for a transactional service in a web application?Multiple choiceHard
  49. When using Spring's @Transactional, which of the following could cause a method's transaction to not rollback on a runtime exception?Multiple choiceHard
  50. Which Spring annotation is used to define a class as a Spring Boot application entry point?Multiple choiceEasy