Spring Framework Technology & Digital Applications 3 β Questions and Answers
Question 1: Which Spring Data interface should you extend to get CRUD operations plus pagination and sorting out of the box?
- CrudRepository
- Repository
- PagingAndSortingRepository
- JpaRepository (Correct answer)
Correct answer: JpaRepository
JpaRepository extends PagingAndSortingRepository and CrudRepository, adding JPA-specific methods like flush() and batch delete.
Question 2: What happens when you use @Transactional on a method called from within the same class in Spring?
- A new transaction is always started regardless
- The transaction annotation is ignored because Spring AOP uses proxies (Correct answer)
- Spring uses AspectJ weaving to enforce the transaction
- An exception is thrown at application startup
Correct answer: The transaction annotation is ignored because Spring AOP uses proxies
Spring's default proxy-based AOP intercepts calls from outside the bean; internal self-invocation bypasses the proxy and thus the @Transactional behavior.
Question 3: In Spring Batch, what is the purpose of the ItemProcessor interface?
- Reads items from a data source one at a time
- Writes a list of processed items to a destination
- Transforms or filters an item between reading and writing (Correct answer)
- Manages transaction boundaries for each chunk
Correct answer: Transforms or filters an item between reading and writing
ItemProcessor sits between the ItemReader and ItemWriter in a chunk-oriented step and can transform, validate, or filter each item.
Question 4: Which actuator endpoint exposes the application's live health indicators?
- /actuator/info
- /actuator/metrics
- /actuator/health (Correct answer)
- /actuator/status
Correct answer: /actuator/health
The /actuator/health endpoint aggregates all registered HealthIndicator beans to report application and dependency health.
Question 5: What is the default scope of a Spring bean?
- prototype
- request
- session
- singleton (Correct answer)
Correct answer: singleton
Beans are singleton-scoped by default, meaning the Spring container creates exactly one instance per application context.
Question 6: Which Spring annotation is used to inject values from a properties file into a field?
- @Autowired
- @Resource
- @Value (Correct answer)
- @Inject
Correct answer: @Value
@Value uses Spring Expression Language (SpEL) syntax like @Value("${property.key}") to inject property values from the environment.
Question 7: In a Spring MVC application, what does @ResponseBody do?
- Maps the return value to a specific HTTP status code
- Serializes the return value directly into the HTTP response body (Correct answer)
- Redirects the user to a named view template
- Binds the HTTP request body to a method parameter
Correct answer: Serializes the return value directly into the HTTP response body
@ResponseBody tells the dispatcher servlet to pass the return value through a message converter instead of rendering a view.
Which Spring Data interface should you extend to get CRUD operations plus pagination and sorting out of the box?