gpt4 book ai didi

java - 无法找到 JNDI 资源 Tomcat 7

转载 作者:行者123 更新时间:2023-11-30 03:31:41 24 4
gpt4 key购买 nike

在我的测试机器上的 Eclipse 中一切正常,但是当我将 WAR 部署到服务器时,每次尝试连接数据库时都会收到“无法定位 JNDI 资源”错误。

我正在使用 WEB-INF/context.xml 中的资源。 mysql-connector-java-5.1.25-bin.jar 位于应用程序的 lib 文件夹中。我已经尝试了我能想到的一切。我假设它是一个 tomcat 特定的问题,因为它在 eclipse 中的 tomcat 安装上运行良好。我缺少什么设置吗?

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/appointmentree" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
url="jdbc:mysql://1.1.1.1/appointmentree"
driverClassName="com.mysql.jdbc.Driver"
username="appointmentree" password="password"
/>
</Context>

产生的错误:

fm.sprout.java.db.DatabaseConnectionException: appointmentree is missing in JNDI.
fm.sprout.java.db.DBConnection.<init>(DBConnection.java:17)
fm.sprout.java.db.MySqlDBHandler.find(MySqlDBHandler.java:108)
com.appointmentree.db.DBUser.findAll(DBUser.java:173)
com.appointmentree.db.DBUser.find(DBUser.java:146)
com.appointmentree.db.DBUser.find(DBUser.java:142)
com.appointmentree.obj.User.getInstance(User.java:39)
com.appointmentree.seeds.Login$1.handle(Login.java:39)
fm.sprout.java.forms.FormHandler.init(FormHandler.java:53)
fm.sprout.java.views.SeedBuilder.post(SeedBuilder.java:103)
com.appointmentree.seeds.Login.onLoad(Login.java:33)
fm.sprout.java.views.SeedPlanter.sow(SeedPlanter.java:131)
fm.sprout.java.session.RequestHandler.doPost(RequestHandler.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
com.appointmentree.session.UserSessionFilter.doFilter(UserSessionFilter.java:72)
root cause

javax.naming.NamingException: com.mysql.jdbc.Driver
org.apache.naming.NamingContext.lookup(NamingContext.java:859)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:153)
org.apache.naming.NamingContext.lookup(NamingContext.java:830)
org.apache.naming.NamingContext.lookup(NamingContext.java:167)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:156)
javax.naming.InitialContext.lookup(InitialContext.java:411)
fm.sprout.java.db.DBConnection.<init>(DBConnection.java:15)
fm.sprout.java.db.MySqlDBHandler.find(MySqlDBHandler.java:108)
com.appointmentree.db.DBUser.findAll(DBUser.java:173)
com.appointmentree.db.DBUser.find(DBUser.java:146)
com.appointmentree.db.DBUser.find(DBUser.java:142)
com.appointmentree.obj.User.getInstance(User.java:39)
com.appointmentree.seeds.Login$1.handle(Login.java:39)
fm.sprout.java.forms.FormHandler.init(FormHandler.java:53)
fm.sprout.java.views.SeedBuilder.post(SeedBuilder.java:103)
com.appointmentree.seeds.Login.onLoad(Login.java:33)
fm.sprout.java.views.SeedPlanter.sow(SeedPlanter.java:131)
fm.sprout.java.session.RequestHandler.doPost(RequestHandler.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
com.appointmentree.session.UserSessionFilter.doFilter(UserSessionFilter.java:72)

web.xml 中的资源

<resource-env-ref>
<resource-env-ref-name>jdbc/appointmentree</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>

最佳答案

尝试使用这个:

<resource-ref>
<res-ref-name>jdbc/appointmentree</res-ref-name>
<res-ref-type>javax.sql.DataSource</res-ref-type>
<res-auth>Container</res-auth>
</resource-ref>

我从这里获得此信息:http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions

关于java - 无法找到 JNDI 资源 Tomcat 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com