Announcement Announcement Module
Collapse
No announcement yet.
Is there a way to configure bean inheritance using annotations? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to configure bean inheritance using annotations?

    Hello,everyone! I'm new to spring, and find it very useful. In a web project, I annotated the DAOs, sevices and actions with @Repository, @Service, @Controller, and configure them using <context:component-scan base-package="sampl.x">.
    I define a GenericDAO, which deals with getting sessions and CRUD processes. So any subclass just extends AbstractGenericDAO ( implements GenericDAO), and has CRUD ability. I know I can configure the bean inheritance relationship in a applicationContext.xml like this:
    Code:
    <bean id="abstractGenericDAO" abstract="true"> 
    <property name="sessionFactory" ref="sessionFactory"/> 
    </bean> 
    
    
    <bean id="testDao" class="sample.TestDaoImpl" parent="abstractGenericDAO" />
    But in this way, I have to define a bean for every concret DAO in the xml file. I prefer the <context:component-scan. I wonder is threre a way to do this with annotations?

    I appreciate any hints or reference

  • #2
    I prefer the <context:component-scan. I wonder is threre a way to do this with annotations?
    Just try it, I think should work for your DAO classes, if you receive some error post the complete error stack trace, consider include names for each @Repository and consider @Qualifier (furthemore of @Autowired) to avoid conflicts

    Let us know your advance

    Comment


    • #3
      Also consider Spring Data Project. They have all that you wish, including nice basic CRUD support available right out of the box.

      Comment

      Working...
      X