如何在 Tomcat 服务器上配置 Servlet 并修复 javax.naming.NameNotFoundException?
How to configure Servlet on Tomcat Server and fix javax.naming.NameNotFoundException?
最近我在 Tomcat 服务器上部署了一个应用程序。它不工作,因为应用程序找不到 Servlet。我认为 web.xml
中的 servlet-class 没问题,但显然 syntax/mapping 是错误的,因为他们找不到它...
web.xml
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>controller.ControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
catalina.log
INFO myapp.com-startStop-2 org.apache.catalina.startup.HostConfig - Deployment of web application archive /home/username/tomcat/webapps/myapp.com/ROOT.war has finished in 442 ms
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.startup.HostConfig - Reloading context []
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.StandardContext - Reloading Context with name [] has started
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.ContainerBase.[Catalina].[myapp.com].[/] - Marking servlet ControllerServlet as unavailable
ERROR ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.ContainerBase.[Catalina].[myapp.com].[/] - Servlet threw load() exception
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.catalina.core.DefaultInstanceManager.lookupFieldResource(DefaultInstanceManager.java:603)
at org.apache.catalina.core.DefaultInstanceManager.processAnnotations(DefaultInstanceManager.java:491)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:174)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4923)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5209)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3775)
at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1307)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1290)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1474)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:280)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1141)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
at java.lang.Thread.run(Thread.java:745)
It's not working because the app can't find the Servlet.
错了。
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].
在命名资源中找不到名称controller.ControllerServlet
您正在使用的地方java:comp/.../controller.ControllerServlet/categoryFacade
.
我建议您首先查看您使用 categoryFacade
的位置。
最近我在 Tomcat 服务器上部署了一个应用程序。它不工作,因为应用程序找不到 Servlet。我认为 web.xml
中的 servlet-class 没问题,但显然 syntax/mapping 是错误的,因为他们找不到它...
web.xml
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>controller.ControllerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
catalina.log
INFO myapp.com-startStop-2 org.apache.catalina.startup.HostConfig - Deployment of web application archive /home/username/tomcat/webapps/myapp.com/ROOT.war has finished in 442 ms
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.startup.HostConfig - Reloading context []
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.StandardContext - Reloading Context with name [] has started
INFO ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.ContainerBase.[Catalina].[myapp.com].[/] - Marking servlet ControllerServlet as unavailable
ERROR ContainerBackgroundProcessor[StandardEngine[Catalina]] org.apache.catalina.core.ContainerBase.[Catalina].[myapp.com].[/] - Servlet threw load() exception
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
at org.apache.catalina.core.DefaultInstanceManager.lookupFieldResource(DefaultInstanceManager.java:603)
at org.apache.catalina.core.DefaultInstanceManager.processAnnotations(DefaultInstanceManager.java:491)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:174)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4923)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5209)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3775)
at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1307)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1290)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1474)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:280)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1141)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
at java.lang.Thread.run(Thread.java:745)
It's not working because the app can't find the Servlet.
错了。
javax.naming.NameNotFoundException: Name [controller.ControllerServlet/categoryFacade] is not bound in this Context. Unable to find [controller.ControllerServlet].
在命名资源中找不到名称controller.ControllerServlet
您正在使用的地方java:comp/.../controller.ControllerServlet/categoryFacade
.
我建议您首先查看您使用 categoryFacade
的位置。