Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Autowiring services >1 deep(Having problems wiring a chain of services)
Autowiring services >1 deep [message #924232] Wed, 26 September 2012 16:33 Go to next message
Justin Stewart is currently offline Justin StewartFriend
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

Re: Autowiring services >1 deep [message #926091 is a reply to message #924232] Fri, 28 September 2012 09:45 Go to previous messageGo to next message
Glyn Normington is currently offline Glyn NormingtonFriend
Messages: 1222
Registered: July 2009
Senior Member
Did you configure annotations in the middle tier bundle? See: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-annotation-config
Re: Autowiring services >1 deep [message #926381 is a reply to message #926091] Fri, 28 September 2012 15:59 Go to previous messageGo to next message
Justin Stewart is currently offline Justin StewartFriend
Messages: 6
Registered: September 2012
Junior Member
Thanks, Glyn - I've gotten it to work using a combination of steps, though I'm not sure all of them are necessary or desired. I've been on a project using different technologies for a few years, so I'm rusty. Anyway, I've added this to the module-context.xml:

<context:load-time-weaver aspectj-weaving="on"/>
<context:spring-configured />
<context:annotation-config />
<context:component-scan base-package="userviceproto.bus" />


And then added the @Configurable annotation to my classes that contain autowired fields.
I wonder if any of these are undesirable as it seems overkill for this issue.

Thanks.
Justin
Re: Autowiring services >1 deep [message #929084 is a reply to message #926381] Mon, 01 October 2012 07:54 Go to previous message
Glyn Normington is currently offline Glyn NormingtonFriend
Messages: 1222
Registered: July 2009
Senior Member
I was hoping that the annotation-config element would suffice, but I'm no expert.
Previous Topic:ClassNotFoundException: org.springframework.context.config.ContextNamespaceHandler
Next Topic:Spring Web Services & Virgo 3.0.x
Goto Forum:
  


Current Time: Thu Mar 28 18:25:36 GMT 2024

Powered by FUDForum. Page generated in 0.02856 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top