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