Reputation: 4617
May @Repository annotation be inherited?
May I create a
@Repository
public abstract class BaseRepository {
}
and then extend it without specifying @Repository annotation?
public class MyRepository extends BaseRepository {
}
How do I know if an annotation can be inherited?
Upvotes: 4
Views: 2635
Reputation: 16035
Annotations aren't inherited by subclasses by default, unless annotated themselves with @Inherited (see James Kingsbery's comment below), and even then only when they are used at class-level. @Repository-annotation itself is not annotated (I checked from the code) with @Inherited, so you'll have to annotate the subclass separately.
Upvotes: 2
Reputation: 7486
See http://www.docjar.com/html/api/org/springframework/stereotype/Repository.java.html
There is no @Inherited annotation, so it is not inherited.
Upvotes: 6
Reputation: 597116
No. The documentation about stereotypes says nothing about it.
Also, imagine the case when you specify a name @Repository("foo")
- then each subclass will be named foo
, which will lead to an exception (duplicate names)
Upvotes: 6