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)
- Why does placing @Valid on a request body parameter in a Spring Boot controller method change runtime behavior?Multiple choiceMedium
- How does using a DTO prevent exposing sensitive data in a REST API?Multiple choiceMedium
- Why does self-invocation of a method with @Transactional annotation not work as expected in Spring?Multiple choiceHard
- Why does @Autowired in Spring matter in this design?Multiple choiceEasy
- 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
- Which annotation would you use to enable transaction management in a Spring Boot application?Multiple choiceEasy
- In a Spring Boot application, what is a potential risk of using self-invocation for a method annotated with @Transactional?Multiple choiceMedium
- What default scope does Spring assign to a bean if no specific scope is declared?Multiple choiceEasy
- Why does self-invocation of a method with a @Transactional annotation not work in a Spring application?Multiple choiceHard
- 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
- Which Spring Boot annotation can be used to combine multiple other annotations commonly used in @Configuration classes?Multiple choiceMedium
- Why does the @Autowired annotation in Spring matter in this design?Multiple choiceEasy
- What challenge does transaction self-invocation pose in Spring, and how can it be addressed?Multiple choiceHard
- How can serialization boundaries help prevent data leaks in a Spring Boot application?Multiple choiceHard
- Which Spring annotation is used to automatically wire a bean into another?Multiple choiceEasy
- Which of the following is true about Spring's proxy-based transaction management?Multiple choiceEasy
- Why does a @RestController in a Spring Boot application matter in this design?Multiple choiceEasy
- In a typical Spring Boot application, where should transaction management be applied?Multiple choiceMedium
- Why do application properties and profiles matter in a production Spring Boot app?Multiple choiceMedium
- In a Spring Boot application, how can you programmatically activate a specific profile?Multiple choiceHard
- Which scope of a bean in Spring is the default in Java?Multiple choiceEasy
- How would you explain a potential issue with using a Prototype scoped bean in a Singleton bean in an interview?Multiple choiceEasy
- What does the @Bean annotation indicate in a Spring Boot application?Multiple choiceEasy
- Why might you choose prototype scope for a Spring bean in a multi-threaded environment?Multiple choiceMedium
- Why is it important to avoid exposing the password field in a User entity via a REST API?Multiple choiceMedium
- In Spring Boot, how can you exclude a specific auto-configuration class from being applied?Multiple choiceMedium
- How should a @Service layer method be structured in a Spring Boot application?Multiple choiceMedium
- In Spring Boot, what is the default scope of a bean?Multiple choiceEasy
- Which of the following is NOT a benefit of using Spring's Dependency Injection?Multiple choiceEasy
- How can you configure a Spring Boot application to reject invalid requests at the controller level?Multiple choiceHard
- In what scenario is it beneficial to use a Prototype scope bean over a Singleton in Spring Boot?Multiple choiceHard
- How can you resolve the issue of transaction self-invocation in Spring?Multiple choiceHard
- Which of the following is a key benefit of using constructor injection in Spring Boot?Multiple choiceMedium
- Why does a transaction-managed method invokes another method in the same class directly cause a problem in practice?Multiple choiceMedium
- How does constructor injection benefit a Spring Boot application?Multiple choiceEasy
- In a Spring Boot application, which layer should handle the conversion of HTTP requests to business operations?Multiple choiceEasy
- Which annotation should be used to indicate a class as a Spring Data Repository?Multiple choiceEasy
- How does Spring Boot differentiate between @Repository and @Service annotations?Multiple choiceMedium
- Which bean scope would you use in a Spring application to ensure a new bean instance is created for each HTTP request?Multiple choiceMedium
- In Spring Boot, what happens when a class is annotated with @Component?Multiple choiceEasy
- Why might a transaction not roll back even if a RuntimeException is thrown?Multiple choiceMedium
- How does Spring handle transactions when methods marked with @Transactional are called from different beans?Multiple choiceMedium
- Which of the following scopes is NOT a valid Spring bean scope?Multiple choiceMedium
- Why is it generally a bad practice to expose database entities directly in a Spring Boot API?Multiple choiceEasy