Question

I am using spring+struts2 and I have a large number of action classes that required a single service (mailService). Instead of injecting service into these action classes, I am wondering is there a way to create a parent class and inject the resources and then have all these classes extending the parent. So I do no need to repeat the injection in each class.

Thanks in advance

Was it helpful?

Solution

try defining a baseClass with a setter method for the mailService. your action classes can all extend this baseClass.

ie

<!-- parent class with the mailService injected -->
<bean name="baseAction" class="..." abstract="true">
    <property name="mailService" ref="mailService"/>
</bean>

<bean name="someAction" class="..." parent="baseAction" >
</bean>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top