I've searched for an answer to this question without success, so I'll post the problem I'm facing. It's simple really, but how do I do this?
I have a DAO that needs a DataSource. Then, I have a Service that uses this DAO. Finally, I want to provide the Service to other users, and let them specify the DataSource. How do I "forward" the DataSource that the user provided, to the DAO?
If my design is wrong, do not hesitate to point this out and suggest a better design.
Ideally I want the user to be able to do this:
where the user has defined his own "dataSource" definition. Then they can inject "myService" wherever they need to use it.
<bean id="myService" parent="service">
<property name="dataSource" ref="dataSource"/>
In the module I am providing, I have:
So userDao needs a DataSource to be configured, but I want this to be left "abstract" until the external user provides it to the service. When that happens, I want to "forward" this dataSource to the userDao. I can't figure out how to do this.
<bean id="userDao" class="p.UserDaoImpl">
<!-- property name="dataSource" ref="dataSource"/ -->
<bean id="service" class="p.Service" abstract="true">
<property name="userDao" ref="userDao"/>
Any help or suggestion of a better approach to achieve this result would be greatly appreciated.
Thanks in advance.