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