JNDI connection in AEM server using spring | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Gaurav-Behl
Gaurav-BehlAccepted solution
Level 10
Apr 23, 2019 7:25 PM UTC

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

  1. Configure the DataSource from OSGi config for PID org.apache.sling.datasource.JNDIDataSourceFactory
  2. 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

6 replies

Gaurav-Behl
Gaurav-BehlAccepted solution
Level 10
Apr 23, 2019 7:25 PM UTC

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

  1. Configure the DataSource from OSGi config for PID org.apache.sling.datasource.JNDIDataSourceFactory
  2. 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

Translate
smacdonald2008
Level 10
Apr 23, 2019 2:08 PM UTC

Looks like they are attempting to connect to a database as if they are working in a SPRING MVC project. Something like - https://www.journaldev.com/2597/spring-datasource-jndi-with-tomcat-example

However - as i have pointed out, AEM is not a Spring based framework and therefore to connect to a database, one should work in the way that AEM connects to databases - which is using a DATASOURCEPOOL.

Translate
joerghoh
Employee
Apr 23, 2019 10:22 AM UTC

Can you please elaborate on bit on this? From your posts I don't get a clear understanding what you are trying to achieve.

Jörg

Translate
smacdonald2008
Level 10
Apr 23, 2019 3:53 AM UTC

I can say it’s not best practice. I recommend following best practice which is DataSoucePool to access a database from AEM.

Translate
Level 2
Apr 23, 2019 3:50 AM UTC

We are consuming one customized jar which is using spring framework. So, we need JNDI connection to connect with other database.is it possible ?

Translate
smacdonald2008
Level 10
Apr 22, 2019 2:17 PM UTC

AEM is not a Spring-based framework. Why would you have a requirement that is based on a framework that AEM is not? AEM uses DataSourcePool API to access databases via an OSGi bundle.

Translate