Bird
0
0

Which of the following is the correct way to define a repository interface in Spring Boot following enterprise patterns?

easy📝 Syntax Q3 of 15
Spring Boot - Advanced Patterns
Which of the following is the correct way to define a repository interface in Spring Boot following enterprise patterns?
Apublic interface UserRepository implements JpaRepository<User, Long> {}
Bpublic class UserRepository implements JpaRepository<User, Long> {}
C@Repository public class UserRepository {}
Dpublic interface UserRepository extends JpaRepository<User, Long> {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall repository pattern syntax

    In Spring Boot, repository interfaces extend JpaRepository to inherit data access methods.
  2. Step 2: Check syntax correctness

    public interface UserRepository extends JpaRepository {} correctly declares an interface extending JpaRepository. public class UserRepository implements JpaRepository {} wrongly uses class with implements. @Repository public class UserRepository {} misses extending JpaRepository. public interface UserRepository implements JpaRepository {} incorrectly uses 'implements' with interface.
  3. Final Answer:

    public interface UserRepository extends JpaRepository<User, Long> {} -> Option D
  4. Quick Check:

    Repository interface syntax = extends JpaRepository [OK]
Quick Trick: Repository is an interface extending JpaRepository [OK]
Common Mistakes:
  • Using class instead of interface for repository
  • Using 'implements' keyword with interface
  • Not extending JpaRepository interface

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes