Bird
0
0

You want to create a custom annotation that combines @Component and @Scope("prototype") to simplify bean definitions. How should you define it?

hard📝 Application Q8 of 15
Spring Boot - Spring Annotations
You want to create a custom annotation that combines @Component and @Scope("prototype") to simplify bean definitions. How should you define it?
A@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Component @Scope("prototype") public @interface MyBean {}
B@Component @Scope("prototype") public @interface MyBean {}
C@Component @Scope("prototype") @interface MyBean {}
D@Component @Scope("prototype") public class MyBean {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to create custom annotations

    Custom annotations need @Target and @Retention to specify usage and lifecycle.
  2. Step 2: Check which option includes these and combines annotations correctly

    Only @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Component @Scope("prototype") public @interface MyBean {} includes @Target, @Retention, and the combined annotations properly.
  3. Final Answer:

    @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Component @Scope("prototype") public @interface MyBean {} -> Option A
  4. Quick Check:

    Custom annotation needs @Target and @Retention [OK]
Quick Trick: Add @Target and @Retention when creating custom annotations [OK]
Common Mistakes:
  • Omitting @Target and @Retention
  • Defining annotation as a class
  • Missing public modifier on annotation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes