Question 1 of 30
In a Spring Data REST application, you are tasked with implementing a custom repository for managing a collection of `Book` entities. Each `Book` has a title, author, and publication year. You need to ensure that when a new `Book` is created, it automatically assigns a unique identifier and validates that the publication year is not in the future. Which of the following approaches would best achieve this functionality while adhering to Spring Data REST conventions?
Implement a custom `@Repository` interface that extends `PagingAndSortingRepository`, and use an `@EventListener` to handle the `BeforeSave` event for validation and ID assignment.
Create a standard `@RestController` that manually handles HTTP requests for `Book` entities, including validation and ID assignment.
Use a `@Service` class to manage the business logic and manually invoke the repository methods for saving `Book` entities without leveraging Spring Data REST features.
Define a custom `@ControllerAdvice` to intercept all requests to the `Book` repository and perform validation and ID assignment globally.

Preparing for VMWare 2V0-72.22 Professional Develop VMware Spring? Now land the interview.

73% of qualified candidates get rejected because of weak resumes. Build an ATS-optimized, recruiter-ready resume in under 5 minutes - free to start.

Build My Resume Free