How To Setup Jndi Database Connection Puddle Inwards Tomcat - Boundary Tutorial Example

Setting the JNDI Database Connection puddle inwards Spring as well as Tomcat is pretty easy. Tomcat server documentation gives plenty information on how to setup connexion puddle inwards Tomcat 5, half-dozen or 7. Here nosotros volition utilisation Tomcat seven along amongst saltation framework for creating a connexion puddle inwards Tomcat server as well as accessing them inwards Spring using JNDI code. In our concluding article, nosotros bring seen how to setup database connexion puddle inwards Spring for essence Java application which doesn't run on a spider web server or application server as well as doesn't bring managed J2EE container. but if you lot are developing a spider web application than its ameliorate to utilisation server managed connexion pool as well as access them using JNDI. Spring configuration volition live on generic as well as exactly based on JNDI refer of Datasource thence it volition function on whatever J2EE Server e.g. Glassfish, WebLogic, JBoss or WebSphere until JNDI refer is same. 

Btw, Tomcat is my favorite web server as well as I utilisation it a lot on evolution every bit it comes integrated amongst IDE similar Eclipse as well as Netbeans. I am using it for all exam as well as evolution purpose, as well as many companies fifty-fifty run Tomcat inwards Production for hosting Java spider web application. 

It's simple, fast as well as rattling robust, though beware amongst java.lang.OutOfMemoryError: PermGen infinite inwards tomcat, which tin give the sack get a retentiveness leak inwards Java application. It unremarkably happens due to ThreadLocal variables as well as JDBC drivers but you lot tin give the sack sure as shooting avoid that yesteryear knowing more



How to utilisation JNDI database connexion puddle inwards Tomcat as well as Spring

There 3 steps to configure as well as run JNDI Datasource Connection pool for any  Java Web application:

1) Configure information source inwards Server as well as create JNDI name.
2) Configure web.xml
3) Configure Spring edible bean amongst JNDI Datasource
4) Include JDBC driver library on Server lib e.g. tomcat/lib


In social club to create JNDI DataSource on J2EE spider web server you lot ask to follow server documentation. On Tomcat half-dozen you lot tin give the sack but seat next slice of XML in context.xml to create Tomcat managed database connexion pool:



<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/springDataSourceDemo">
<Resource name="jdbc/springeDataSource"
         auth="Container"
         type="javax.sql.DataSource"
         driverClassName="oracle.jdbc.driver.OracleDriver"
         url="jdbc:oracle:thin:@localhost:1521:SPRING_TEST"
         username="root"
         password="root"
         removeAbandoned="true"
         removeAbandonedTimeout="90"
         logAbandoned="true"
         maxActive="20"
         maxIdle="10"
         maxWait="-1"/>
</Context>


Resource chemical factor volition create JNDI information source which tin give the sack live on referenced using JNDI refer "jdbc/springeDataSource". 

Tomcat internally utilisation DBCP as well as Commons puddle library for managing database connexion pool. You tin give the sack banking concern jibe tomcat/lib directory for appall file tomcat-dbcp.jar which is responsible for creating database connexion puddle within tomcat server.




1. web.xml configuration to access JNDI Database connexion pool

In social club to access whatever server resources from your spider web application, you lot ask to specify the JNDI resources inwards web.xml. 

You can utilisation the next XML to declare JNDI Datasource inwards web.xml:

 <resource-ref>
        <description>Oracle Spring JNDI Datasource</description>
        <res-ref-name>jdbc/springDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
</resource-ref>

Now your spider web application volition run across JNDI Datasource created inwards tomcat amongst refer jdbc/springDataSource

Btw, if you lot are non familiar amongst JNDI as well as other Java EE concepts thence I start propose you lot acquire through JDBC driver appall file. I unremarkably seat JAR file within lib directory of tomcat but you lot tin give the sack seat it anywhere it makes feel as well as modifies tomcat classpath to include driver JAR into classpath. 


Now the residue of code which uses this information source should rest the same. You tin give the sack acquire Spring DAO source from the previous article How to setup Database Connection puddle inwards Spring framework.

Setting the JNDI Database Connection puddle inwards Spring as well as Tomcat is pretty slow How to setup JNDI Database Connection puddle inwards Tomcat - Spring Tutorial Example




Other Spring Framework Tutorials as well as Resources for farther learning
Spring Framework 5: Beginner to Guru
Spring as well as Hibernate Guide for Beginners

Thanks for reading this article thence far. If you lot similar this article thence delight part amongst your friends as well as colleagues. If you lot bring whatever questions or feedback thence delight drib a note.


P.S. - If you lot desire to acquire how to prepare RESTful Web Service using Spring MVC inwards depth, I propose you lot bring together the REST amongst Spring certification class yesteryear Eugen Paraschiv. One of the best course of written report to acquire REST amongst Spring MVC.



Sumber https://javarevisited.blogspot.com/

0 Response to "How To Setup Jndi Database Connection Puddle Inwards Tomcat - Boundary Tutorial Example"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel