Results 1 to 10 of 10

Thread: OSGi and @Configurable

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    4

    Default OSGi and @Configurable

    I have some problems with @Configurable used together with Spring-DM under Equinox (in an RCP application). I'd like to inject a reference pointing to a bean referenced using osgi:reference (sensorConfigProvider) into a bean not instantiated by Spring (SensorView), but it does not work.
    My config:

    <context:annotation-config/>

    <context:spring-configured/>

    <osgi:reference id="sensorConfigProvider" interface="configprovider.ISensorConfigProvider" />

    <bean class="ui.SensorView"/>

    and the class definition:

    @Configurable
    public class SensorView extends ViewPart {

    @Autowired
    private ISensorConfigProvider sensorConfigProvider;

    ...
    }

    Am I missing something?

  2. #2
    Join Date
    Aug 2006
    Posts
    236

    Default

    How are you applying the aspect? LTW or build time? If you're using LTW have made sure you've got the correct parameters?

    have a look at my blog which does the @Configurable stuff
    www.amin-mc.blogspot.com

  3. #3
    Join Date
    Feb 2008
    Posts
    4

    Default

    Thanks, Amin. Your blog entry is clear, but I did more or less the same and it does not work.
    Additionally, I got an exception:

    org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from URL [bundleentry://39/META-INF/spring/beans.xml];
    nested exception is java.lang.IllegalArgumentException: pattern matching is unsupported for class space lookups

    So again,

    beans.xml:

    <context:annotation-config />
    <context:spring-configured />
    <context:load-time-weaver />
    <context:component-scan base-package="acme.sensors" />

    <osgi:reference id="sensorConfigProvider" interface="acme.sensors.configprovider.ISensorConf igProvider" />

    <bean class="acme.sensors.ui.SensorView"/>

    startup parameters:

    "C:\Program Files\Java\jdk1.6.0_03\bin\java.exe" -Xbootclasspath/a:lib/aspectjrt.jar -javaagent:lib/spring-agent.jar -jar plugins\org.eclipse.equinox.launcher_1.0.100.v2007 1211.jar -console -consolelog -configuration configuration

    bean:

    @Configurable(dependencyCheck=true)
    public class SensorView extends ViewPart {

    public static final String ID = "SensorConfigUi.sensorView";

    @Autowired
    private ISensorConfigProvider sensorConfigProvider;

    ...
    }

  4. #4
    Join Date
    Aug 2006
    Posts
    236

    Default

    Hmmm...

    I'm not sure to be honest. This looks more of an OSGi configuration. I'll need to have a look. I might try to replicate your problem with a test app.

  5. #5
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    Given how the load time weaver works and the dynamic nature of OSGi I would imagine its possible at the time that the code gets woven, the ISensorConfigProvider service isn't available. What happens if you use a normal Spring bean that implements ISensorConfigProvider using some sort of stub implementation? If that works, but the osgi doesn't, then perhaps a post in the OSGi forum would be in order.

    It sounds like it should work because you'd figure that when the osgi reference is made a proxy implementing the interface is created.

    As for the XML error, it sounds like there is something wrong with the header of your XML. Can you post it?
    Bill

  6. #6
    Join Date
    Feb 2008
    Posts
    4

    Default

    I've tried using plain Spring beans without OSGi references, but I got the same.

    The headers of my beans.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:osgi="http://www.springframework.org/schema/osgi"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/osgi http://www.springframework.org/schem...pring-osgi.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    The exception is thrown when I use the <context:component-scan ...> tag.
    Last edited by sragli; Feb 14th, 2008 at 09:07 AM.

  7. #7
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Annotation scanning was addressed in Spring-DM 1.1.0. M1 has been released while M2 is scheduled for end of April, beginning of May.
    The generic problem is that scanning relies on classpath pattern matching which is quite difficult inside an OSGi environment since there is no file system and there can be multiple spaces to search into (as the classes can be in other bundles that are imported into the main one).
    Note that currently meta-annotations scanning (@Component) work if you're using Spring 2.5.4 (not released yet) due to a subtle class loading problem that was fixed in HEAD.
    Cheers,
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •