This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring annotation with inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring annotation with inheritance" Watch "Spring annotation with inheritance" New topic

Spring annotation with inheritance

everson santos
Ranch Hand

Joined: Jul 11, 2009
Posts: 50

I'm trying build a project with spring and I have some generic classes and I'd like know if when I have inheritance, the annotation will go to be inherited too ? For example:

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Yes they do. Some people put their annotation on their interfaces.

Based on the code you wrote I have two comments about the abstract class.

1) You are using JPA and injecting the EntityManager, there is absolutely no reason why you need to extend HibernateDaoSupport. You are not gaining anything by it and now you are tightly coupling your code with a Spring specific class.
2) You are putting a bean name in your @Repository annotation, but plan to extend it by many Repository classes, which each will need their own distinct name. Spring will automatically give it a name, and since you are going the route of annotations, then it is assumed you are auto wiring, which spring does by type, so a name besides what Spring automatically generates is enough.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
subject: Spring annotation with inheritance
Similar Threads
How to inject EntityManager via setter in spring
Generic DAO and Generic Stored Procedure in Spring Framework 2.5.6
Generic of a Generic
org.springframework.beans.factory.BeanCreationException: Error creating bean with name...
Question about generic