This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring annotation with inheritance" Watch "Spring annotation with inheritance" New topic
Author

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring annotation with inheritance