使用部署在 Apache Tomcat 上的 Clojure 创建的 WAR 不运行 Servlet
我创建了 Compojure 入门页面 中给出的示例 WAR 并进行了部署到 Apache Tomcat 6.0.2 wepapps 文件夹。我使用的 Web.xml 如下:
<web-app>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>myapp.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
访问 URL 会引发以下错误
java.lang.NullPointerException: Handler returned nil (maybe no routes matched URI)
compojure.http.servlet$request_handler__72.invoke(servlet.clj:110)
myapp.MyServlet$_service__108.invoke(MyServlet.clj:11)
myapp.MyServlet.service(Unknown Source)
我已将 Clojure、Clojure contrib jar 包含在 WEB-INF/lib 文件夹中。
有没有人在 Apache Tomcat 上遇到过 Clojure WAR 的类似问题?
我尝试运行的 Servlet 是:
;; src/myapp/MyServlet.clj
(ns myapp.MyServlet
(:use compojure)
(:gen-class
:extends javax.servlet.http.HttpServlet))
(defroutes greeter
(GET "/"
(html [:h1 "Hello World"])))
(defservice greeter)
当我替换 (defservicegreeter)
时,
(run-server {:port 8080}
"/*" (servlet greeter))
我能够运行它并从浏览器访问 URL。
然而,当我从 Apache Tomcat 运行它时,我仍然面临同样的问题。
I created the sample WAR as given at the Compojure Getting Started Page and deployed it to Apache Tomcat 6.0.2 wepapps folder. The Web.xml I used is as below:
<web-app>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>myapp.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Accessing the URL throws the following error
java.lang.NullPointerException: Handler returned nil (maybe no routes matched URI)
compojure.http.servlet$request_handler__72.invoke(servlet.clj:110)
myapp.MyServlet$_service__108.invoke(MyServlet.clj:11)
myapp.MyServlet.service(Unknown Source)
I have included the Clojure, Clojure contrib jars in the WEB-INF/lib folder.
Has anyone encountered similar issue with Clojure WARs on Apache Tomcat ?
The Servlet I am trying to run is :
;; src/myapp/MyServlet.clj
(ns myapp.MyServlet
(:use compojure)
(:gen-class
:extends javax.servlet.http.HttpServlet))
(defroutes greeter
(GET "/"
(html [:h1 "Hello World"])))
(defservice greeter)
When I replaced the (defservice greeter)
with
(run-server {:port 8080}
"/*" (servlet greeter))
I am able to run this and access URL from browser.
However, when I run this from Apache Tomcat, I still face the same issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)你真的定义了路线吗?听起来是一个明显的起点。确保您的路由表存在并且定义正确。您需要类似的东西:
2)尝试在 Jetty 中启动您的应用程序。如果在 Jetty 下也不起作用,并出现同样的错误,那么你的问题不在于 WAR 部署,而在于应用程序。
如果这些都不能解决问题,请为我们提供更多信息,例如您的路由表。
1) Did you actually define routes? Sounds like an obvious place to start. Make sure your routing table exists and is correctly defined. You need something like:
2) Try starting your app in Jetty. If it doesn't work under Jetty either, with the same error, then your problem is not in the WAR deployment but in the app.
If neither of these fixes it, post some more information for us, such as your routing table.
该问题恰好与 defroutes 中使用
"/"
而不是"/*"
有关。如果我将 defroute 定义为:它适用于 Apache Tomcat 6。
The problem happened to be related to the use of
"/"
in the defroutes instead of"/*"
. If I define the defroutes as :It works on Apache Tomcat 6.