79264557

Date: 2024-12-09 10:10:44
Score: 1.5
Natty:
Report link

it can get a service reference from a component in other bundle, but it can't get a service reference inherited from its base class which is in other bundle.

here's the solution in this website OSGI @Component annotation does not include references required by the base class while extending an existing OSGI service

before i add some configuration in pom.xml the compiled directory target/classes/OSGI-INF/org.onosproject.incubator.net.tunnel.impl.TunnelManager.xml

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="org.onosproject.incubator.net.tunnel.impl.TunnelManager" immediate="true" activate="activate" deactivate="deactivate">
  <implementation class="org.onosproject.incubator.net.tunnel.impl.TunnelManager"/>
  <service>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelService"/>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelAdminService"/>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelProviderRegistry"/>
  </service>
  <reference name="store" cardinality="1..1" interface="org.onosproject.incubator.net.tunnel.TunnelStore" field="store"/>
</scr:component>

after i added "-dsannotations-options: inherit" in the plugin in some pom.xml, then i get the reference annotated by @Reference from its base class in TunnelManager.xml

<plugins>
    <plugin>
        <groupId>biz.aQute.bnd</groupId>
        <artifactId>bnd-maven-plugin</artifactId>
        <version>3.5.0</version>
        <executions>
            <execution>
                <id>run-bnd</id>
                <goals>
                    <goal>bnd-process</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <bnd><![CDATA[-dsannotations-options: inherit]]></bnd>
        </configuration>
    </plugin>
</plugins>

    <?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="org.onosproject.incubator.net.tunnel.impl.TunnelManager" immediate="true" activate="activate" deactivate="deactivate">
  <implementation class="org.onosproject.incubator.net.tunnel.impl.TunnelManager"/>
  <service>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelService"/>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelAdminService"/>
    <provide interface="org.onosproject.incubator.net.tunnel.TunnelProviderRegistry"/>
  </service>
  <reference name="eventDispatcher" cardinality="1..1" interface="org.onosproject.event.EventDeliveryService" field="eventDispatcher"/>
  <reference name="store" cardinality="1..1" interface="org.onosproject.incubator.net.tunnel.TunnelStore" field="store"/>
</scr:component>

Thank you this website, it has answer unless you use the correct search key words

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Reference
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: emalovecode