Annotation Inheritance
About
@Inherited Meta-Annotation
@Inherited Meta-Annotation@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation {}Constraints of @Inherited
@InheritedExample: Inheriting a Custom Annotation
Step 1: Define an Inheritable Annotation
Step 2: Apply it to a Base Class
Step 3: Extend the Base Class
Step 4: Access via Reflection
What if @Inherited Is Missing?
@Inherited Is Missing?Annotation Inheritance in Spring
Examples in Spring:
Misconception: Method-Level Inheritance
Subclass of a test class like BaseIT doesn't need to redeclare annotations such as @SpringBootTest
BaseIT doesn't need to redeclare annotations such as @SpringBootTestExample
JUnit + Spring TestContext Framework Use Meta-Reflection
2. Spring Boot’s @SpringBootTest, @ActiveProfiles, etc.
@SpringBootTest, @ActiveProfiles, etc.Last updated