I use org.apache.felix.framework-4.6.1.jar and a bundle
org.apache.felix.scr-1.8.3-SNAPSHOT.jar
And I have two bundles - bundleA and bundleB. => totally I have three bundles
(A,B,scr)
BundleA
#############################################################################################
I have a bundleA with the class TempClass:
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ServiceScope;
@Component(
immediate = false,
scope=ServiceScope.PROTOTYPE
)
public class TempClass implements TempInterface{
private String temp;
@Override
public setTemp(String temp);{...}
@Override
public String getTemp(){...}
}
In order to generate ds file I use the latest version of maven bundle plugin
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
This plugin generates the following ds xml file:
<?xml version="1.0"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"
immediate="false">
<implementation class="TempClass"/>
<service scope="prototype">
<provide interface="TempInterface"/>
</service>
</scr:component>
BundleB
#############################################################################################
In bundle I manually try to get two instances of service:
ServiceReference sr1 = bc.getServiceReference(TempInterface.class);
TempInterface bean1 = (TempInterface)bc.getService(sr1);
bean1.setTemp("I am bean1");
ServiceReference sr2 = bc.getServiceReference(TempInterface.class);
TempInterface bean2 = (TempInterface)bc.getService(sr2);
bean2.setTemp("I am bean2");
System.out.println("Test bean1:"+bean1.getTemp()+",test
bean2:"+bean2.getTemp());
And this is the output:
Test bean1:I am bean2, test bean2:I am bean2
I thought that I would get "Test bean1:I am bean1, test bean2:I am bean2"
What is my mistake?
--
Alex Sviridov