Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

JNDI connection in AEM server using spring

Avatar

Avatar
Validate 1
Level 2
rasikawanjari
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
rasikawanjari
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile
rasikawanjari
Level 2

22-04-2019

we have a requirement  to access a database through a webserver JNDI connection using spring framework

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
Gaurav-Behl
MVP

Likes

248 likes

Total Posts

1,147 posts

Correct Reply

283 solutions
Top badges earned
Establish
Give back 300
Give Back 50
Give Back 5
Give Back 3
View profile
Gaurav-Behl
MVP

23-04-2019

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

Answers (5)

Answers (5)

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

22-04-2019

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.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

23-04-2019

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.

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,118 likes

Total Posts

3,149 posts

Correct Reply

1,073 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,118 likes

Total Posts

3,149 posts

Correct Reply

1,073 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

23-04-2019

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

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,408 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

22-04-2019

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

Avatar

Avatar
Validate 1
Level 2
rasikawanjari
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 1
Level 2
rasikawanjari
Level 2

Likes

6 likes

Total Posts

22 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
View profile
rasikawanjari
Level 2

22-04-2019

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