gpt4 book ai didi

java - JNDI 在服务器初始化函数中抛出 Servlet 异常

转载 作者:行者123 更新时间:2023-11-28 22:41:42 25 4
gpt4 key购买 nike

你好,

我正在尝试将应用程序部署到我的新 Tomcat 托管服务。问题是我现在在服务器初始化函数运行时抛出一个 Servlet 异常。

错误如下:

26-May-2015 12:56:48.668 SEVERE [http-nio-12937-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet Controller
javax.servlet.ServletException
at controller.Controller.init(Controller.java:42)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)

现在,这是我设置数据源的 web.xml 文件:

<Resource name="jdbc/drkplaya_pkRater" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/drkplaya_pkRater"
username="drkplaya_pkRater" password="" initialSize="1" maxActive="30" maxIdle="30"
maxWait="15000" removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true"
validationQuery="select now();"
/>
<servlet>
<description></description>
<display-name>Controller</display-name>
<servlet-name>Controller</servlet-name>
<servlet-class>controller.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/gallery</url-pattern>
</servlet-mapping>

最后,这是调用数据源的初始化函数:

public void init(ServletConfig config) throws ServletException {
try {
InitialContext initContext = new InitialContext();
Context env = (Context) initContext.lookup("java:comp/env");

ds = (DataSource) env.lookup("jdbc/drkplaya_pkRater");

} catch (NamingException e) {
throw new ServletException();
}
}

现在,它在我的本地服务器上 100% 运行,但是在上传它时,我收到上面列出的异常。

我的 init 函数中是否缺少导致此错误的内容?

编辑:有人指出我吞下了 NameException。修复后,我知道有以下错误:

message javax.naming.NameNotFoundException: Name [jdbc/drkplaya_pkRater] is not bound in this Context. Unable to find [jdbc].

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/drkplaya_pkRater] is not bound in this Context. Unable to find [jdbc].
controller.Controller.init(Controller.java:42)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:744)
root cause

javax.naming.NameNotFoundException: Name [jdbc/drkplaya_pkRater] is not bound in this Context. Unable to find [jdbc].
org.apache.naming.NamingContext.lookup(NamingContext.java:818)
org.apache.naming.NamingContext.lookup(NamingContext.java:166)
controller.Controller.init(Controller.java:39)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

最佳答案

您的 mysql 服务器可能运行在与 tomcat 不同的主机上。您将本地主机放在资源配置中。请咨询您的托管服务提供商,您的数据库服务器的主机是什么。

关于java - JNDI 在服务器初始化函数中抛出 Servlet 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30466255/

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