This article describes how to config jndi in tomcat6 and work with hibernate.
step 1) open file context.xml under folder %tomcat_home%/conf,
and add the following settings between <Context> and </Context>
<Resource name="jdbc/leave" auth="Container" type="javax.sql.DataSource"
password="lmsdb1234" username="lms" driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/lmsdb" maxActive="20" maxIdle="1" maxWait="5000"/>
step 2) copy mysql driver file, e.g. mysql-connector-java-5.1.7-bin.jar to folder %tomcat_home%/lib
step 3) open file web.xml for leave project, and add the following settings
<resource-ref>
<description>MySQL DataSource</description>
<res-ref-name>jdbc/leave</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
make sure the refercence name is the same as defined in tomcat config file.
step 4) open hibernate config file and assign the jndi settings
<property name="connection.datasource">
java:/comp/env/jdbc/leave
</property>
本文详细介绍了如何将JNDI配置到Tomcat 6中,并与Hibernate一起工作。具体步骤包括修改Tomcat的context.xml文件以设置数据源参数,复制MySQL驱动到Tomcat的lib目录,更新web.xml文件以引用数据源,以及在Hibernate配置文件中指定JNDI设置。

969

被折叠的 条评论
为什么被折叠?



