Code:public interface BaseDAO { public void setDataSource(DataSource dataSource); } public class BaseDAOImpl implements BaseDAO { public DataSource dataSource; public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } } public class UserDAOImpl extends BaseDAOImpl implements UserDAO { ... } public class CustomerDAOImpl extends BaseDAOImpl implements CustomerDAO { ... }
Now within my dataAccessContext-jdbc.xml
Does anyone know a way to set the dataSource property for the BaseDAOImpl once, and not repeat setting the dataSource in each of the sub classes that derive from BaseDAOImpl?Code:<!-- JNDI lookup of datasouce --> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>jdbc/jhs</value> </property> </bean> <bean id="userDAO" class="com.xyz.dao.impl.UserDAOImpl"> <property name="dataSource"> <ref local="dataSource"/> </property> </bean> <bean id="customerDAO" class="com.xyz.dao.impl.CustomerDAOImpl"> <property name="dataSource"> <ref local="dataSource"/> </property> </bean>
Thanks for your help.


Reply With Quote