Autowiring services >1 deep [message #924232] |
Wed, 26 September 2012 16:33 |
Justin Stewart Messages: 6 Registered: September 2012 |
Junior Member |
|
|
Hi, all -
I have a Spring question for you.
I have three services: web, business, and data. Business and data both export services to Virgo. What I would like is for web to reference the business service and for business to reference the data service, so my chain looks like this:
(user) -> web -> business -> data -> (database)
The data and business services are properly exposed using osgi:service tags and they are referenced properly using osgi:reference tags from the business and web services, respectively.
I am using Spring Autowired to inject the services into my various classes, so the WebController class looks like this:
public class WebController {
@Autowired
private BusInterface bus;
...
and the business class looks like this:
public class BusImpl implements BusInterface {
@Autowired
private DataInterface data;
So, now the problem. The business service is properly autowired into the WebController class, but that business service instance has not been properly autowired with the data service - so data is null in the above BusImpl class.
I can autowire both business and data services directly into the web bundle, so I know they're both working properly, but it's like the autowiring fails when I have a chain of services > 1 deep.
[Update]
Any services I autowire in business are null when the business service is autowired into web, including org.osgi.framework.BundleContext.
But if I autowire the BundleContext in web and pass the BundleContext to the business service, the business service can then get the data service:
ServiceReference<DataInterface> ref = context.getServiceReference(DataInterface.class);
DataInterface data = context.getService(ref);
// Now data is not null
This makes me think that there are no classloader issues here, but a Spring autowiring problem ...
Any ideas about how I can address this?
Thanks so much for the help -
Justin
P.S. I have a running example, if needed.
[Updated on: Wed, 26 September 2012 20:11] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02856 seconds