Should you set up database connection properties in server.xml or context.xml

后端 未结 5 1225
情书的邮戳
情书的邮戳 2020-12-02 04:56

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

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 05:32

    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

提交回复
热议问题