Problem
Can’t get access to DataSourcePool in OSGi bundle in Adobe AEM/CQ5.
Solution
In bundle activator you need to get and store the DataSourcePool and get it in your bundle classes via static method.
Activator.java code
import com.day.commons.datasource.poolservice.DataSourcePool;
public class Activator implements BundleActivator {
private static DataSourcePool source;
public void start(BundleContext context) throws Exception {
ServiceReference dspRef = context.getServiceReference(DataSourcePool.class.getName());
source = (DataSourcePool)context.getService(dspRef);
}
public void stop(BundleContext context) throws Exception {
}
public static DataSourcePool getDataSourcePool(){
return source;
}
}
And you can get the DataSourcePool in your class by simply calling the Activator.getDataSourcePool() method.