A solution to use JNDI in AEM. There could be other solutions as well --
Apache Sling :: DataSource Provider
While running in Application Server the DataSource instance might be managed by app server and registered with JNDI. To enable lookup of DataSource instance from JNDI you can configure JNDIDataSourceFactory
- Configure the DataSource from OSGi config for PID
org.apache.sling.datasource.JNDIDataSourceFactory - Provide the JNDI name to lookup from and other details
If Felix WebConsole is used then you can configure it via Configuration UI at http://localhost:8080/system/console/configMgr/org.apache.sling.datasource.JNDIDataSourceFactory
Once configured JNDIDataSourceFactory would lookup the DataSource instance and register it with OSGi ServiceRegistry