Results 1 to 3 of 3

Thread: Is there a way to configure bean inheritance using annotations?

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Posts
    1

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,791

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Jul 2010
    Posts
    139

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •