I am trying to set up the database connection properties using JNDI for a Spring web application.
I am considering two approaches as below:
Approach
step 1: context.xml
Step 2 : web.xml
DB Connection
refname
javax.sql.DataSource
Container
Step 3 : create a class to get connection
Connection connection = null;
Context context = (Context) new InitialContext().lookup("java:comp/env");
DataSource ds = (DataSource) context.lookup("refname");
connection = ds.getConnection();
Everything is set