How can i get the service ref after i changed org.apache.felix.scr.annotations to org.osgi.service.component.annotations

33 Views Asked by At

the command error

20:25:41.655 ERROR [AtomixManager] bundle org.onosproject.onos-core-primitives:3.0.0.SNAPSHOT (234)[org.onosproject.store.atomix.impl.AtomixManager(67)] : The activate method has thrown an exception
java.lang.ClassCastException: class io.atomix.cluster.protocol.HeartbeatMembershipProtocol$Type cannot be cast to class io.atomix.utils.NamedType (io.atomix.cluster.protocol.HeartbeatMembershipProtocol$Type is in unnamed module of loader io.github.classgraph.ClassGraphClassLoader @3ade9526; io.atomix.utils.NamedType is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @ea65217)
        at io.atomix.core.registry.ClasspathScanningRegistry.lambda$null$1(ClasspathScanningRegistry.java:80)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at io.atomix.core.registry.ClasspathScanningRegistry.lambda$new$2(ClasspathScanningRegistry.java:74)
        at java.base/java.util.Map.computeIfAbsent(Map.java:1003)
        at java.base/java.util.Collections$SynchronizedMap.computeIfAbsent(Collections.java:2682)
        at io.atomix.core.registry.ClasspathScanningRegistry.<init>(ClasspathScanningRegistry.java:68)
        at io.atomix.core.registry.ClasspathScanningRegistry.<init>(ClasspathScanningRegistry.java:43)
        at io.atomix.core.registry.ClasspathScanningRegistry$Builder.build(ClasspathScanningRegistry.java:215)
......
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:328)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:929)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:915)
        at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:133)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:984)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:752)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:674)
        at org.apache.felix.scr.impl.manager.AbstractComponentManager$1.run(AbstractComponentManager.java:461)
        at org.apache.felix.scr.impl.ComponentActorThread.run(ComponentActorThread.java:114)

I add some compile dependency such as in features.xml

<bundle>mvn:org.osgi/org.osgi.resource/1.0.0</bundle>
<bundle>mvn:org.osgi/org.osgi.service.component/1.4.0</bundle>
<bundle>mvn:org.osgi/org.osgi.service.component.annotations/1.4.0</bundle>
<bundle>mvn:org.osgi/org.osgi.service.metatype.annotations/1.4.0</bundle>

but it has nothing to fix the problem this is what i get, i can't fix it the console can't get the bundle or service or component etc. anyone can give some advice for me, thank you in advance!

1

There are 1 best solutions below

0
emalovecode On

the cause is that io.github.classgraph loads class io.atomix.utils.NamedType io.atomix.cluster.protocol.HeartbeatMembershipProtocol$Type while org.apache.felix.framework loads class io.atomix.utils.NamedType, but HeartbeatMembershipProtocol$Type should be typecast to NamedType。

The solved method is to add some DynamicImport-Package attribute in pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>4.1.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <DynamicImport-Package>io.atomix.cluster.*,io.atomix.primitive.*,io.atomix.core.*,io.atomix.protocols.*</DynamicImport-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build> 

so when your bundle is loaded, the dependency jars will be loaded.

thanks those who give me clues!