Announcement Announcement Module
Collapse
No announcement yet.
DI for abstract classes failing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DI for abstract classes failing

    I am having trouble wiring up a bean hierarchy. I have an abstract template class which looks like:

    Code:
     public abstract class ClaimAction extends DefaultAction {
    
        private ClaimManager claimManager;
    
        public void setClaimManager(ClaimManager claimManager) {
            this.claimManager = claimManager;
        }
    
        public void execute() {
            //blah blah some code here
            claimManager.doSomething(); 
            showClaim();
    
        }
    
        private Claim loadClaim(long claimID) {
            return 
        }
    
        /**
         * Subclasses implement this 
         */
        protected abstract ActionForward showClaim();
    }
    And a concrete subclass:

    Code:
    public class ClaimSummaryAction extends ClaimAction {
    
        protected ActionForward showClaim() {
            //show it
        }
    }
    When I try to run the showClaim method on ClaimSummaryAction I get a nullpointer in the superclass as the claimManager is not set.

    My config file looks like:

    Code:
    <bean id = "claimAction" class="com.***.claim.ClaimAction" abstract="true" >
        <property name="claimManager"><ref bean="claimManager" /></property>
    </bean>
    
    <bean id = "claimSummaryAction" parent="claimAction" class="com.***.claim.ClaimSummaryAction" />
    
    <bean id = "claimDAO" class="com.***.claim.ClaimDAO">
        <property name="sessionFactory"><ref bean="mySessionFactory"/></property>
    </bean>
    I need both the abstract class and the subclass to be able to access the claimManager. I realise I must be doing something wrong here, any help much appreciated.

  • #2
    DI for abstract classes failing

    I think you just need to omit the class attribute from your abstract parent bean.

    HTH,
    Fernando

    Comment

    Working...
    X