Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » OSGI reference Bean not found(A referenced OSGI service cannot be injected with @Autowired)
OSGI reference Bean not found [message #717124] Fri, 19 August 2011 11:31 Go to next message
Peter Mucha is currently offline Peter MuchaFriend
Messages: 6
Registered: August 2011
Junior Member
Hi,
I have the following setup:
one WAB, containing a @Controller, which has an attribute @Autowired at a private porperty of interfacetype X
import of osgi-service via <osgi:reference interface="X" id="sid" />


Another Bundle (not web-specific) defining interface X and an implementation
Ximpl (anotated with @Controller("ximpl")).

export of this service via <osgi:service interface="X" ref="ximpl" />

from the virgo admin panel, it looks fine concerning as exporting and importing of service.
under consumed services of the WAB, it says:

org.springframework.osgi.bean.name ximpl
service.id 265
Bundle-SymbolicName HelperBundle
objectClass org.helper.X
Bundle-Version 1.0.0

which means, that the export and import worked.
additionally, there is one Bean in the spring context:
sid $Proxy173 false true

which means, a bean with the name sid (as given in the osgi:reference-tag) exists

now, the final step fails:
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private [...] nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.helper.X]


can someone hopefully point me to my error?
or is it a bug?

thanks, peter

[Updated on: Fri, 19 August 2011 11:33]

Report message to a moderator

Re: OSGI reference Bean not found [message #717213 is a reply to message #717124] Fri, 19 August 2011 15:48 Go to previous messageGo to next message
Peter Mucha is currently offline Peter MuchaFriend
Messages: 6
Registered: August 2011
Junior Member
After some more work on this problem, i have a related question:
i have the following setup in the WAB project:
in META-INF/spring/osgi-context.xml, i define the osgi:reference-bean
in WEB-INF/spring/blabla-context.xml, i define the annotation processing for my @Controller.

could it be, that there are separate contexts in which the beans reside? so that the @Controller cannot find my bean, declared in osgi-context.xml?

i tried to reference the osgi-service in the blabla-context.xml, but virgo (or more specifically, spring) throw me this error:
org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'osgi:reference'.

so it seems to be the only option to reference osgi-xml-namespace in the meta-inf-directory, which sounds kind of weird to me.
am i still on the right way? Smile
Re: OSGI reference Bean not found [message #717246 is a reply to message #717213] Fri, 19 August 2011 17:34 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Peter,

One thing that jumps out is the location of osgi-context.xml in WAB project. Because it sits in /META-INF/spring it might be getting picked up by Spring-osgi extender bundle - that is not what you want. You want that config to be picked up by the ServerOsgiBundleXmlWebApplicationContext in web.xml

example
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/context/applicationContext-osgi.xml
            /WEB-INF/spring/context/applicationContext.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    </context-param>


With this modification you will also need an Import-Package: org.eclipse.virgo.web.dm

If this does not solve your problem, would you mind providing:

1. Your web.xml for WAB project
2. Manifest for WAB project
3. Manifest for Helper project.

This will help in figuring out the details.

Thanks
Dmitry

[Updated on: Fri, 19 August 2011 17:35]

Report message to a moderator

Re: OSGI reference Bean not found [message #717376 is a reply to message #717124] Sat, 20 August 2011 08:40 Go to previous messageGo to next message
Peter Mucha is currently offline Peter MuchaFriend
Messages: 6
Registered: August 2011
Junior Member
bingo, thats it!
thanks for your help, as i saw, this wassnt the first time, you gave this tip Smile

this information is at a very unlikely place in the documentation, i must say...

[Updated on: Sat, 20 August 2011 08:40]

Report message to a moderator

Re: OSGI reference Bean not found [message #844081 is a reply to message #717246] Fri, 13 April 2012 17:11 Go to previous message
R Abreu is currently offline R AbreuFriend
Messages: 7
Registered: April 2012
Junior Member
Thank you for the tip.


Dmitry Sklyut wrote on Fri, 19 August 2011 18:34
Peter,

One thing that jumps out is the location of osgi-context.xml in WAB project. Because it sits in /META-INF/spring it might be getting picked up by Spring-osgi extender bundle - that is not what you want. You want that config to be picked up by the ServerOsgiBundleXmlWebApplicationContext in web.xml

example
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/context/applicationContext-osgi.xml
            /WEB-INF/spring/context/applicationContext.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    </context-param>


With this modification you will also need an Import-Package: org.eclipse.virgo.web.dm

If this does not solve your problem, would you mind providing:

1. Your web.xml for WAB project
2. Manifest for WAB project
3. Manifest for Helper project.

This will help in figuring out the details.

Thanks
Dmitry

Previous Topic:Import-Package weird
Next Topic:Spring DM: No Catalina Service found
Goto Forum:
  


Current Time: Wed Apr 24 23:02:37 GMT 2024

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

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

Back to the top