开始使用liberator

时间:2014-05-17 13:32:04

标签: clojure

我是clojure和解放者的新手。

我正在尝试使用liberator,但我仍然遇到以下错误。

这是启动网络服务器并定义路线的代码:

(ns game-of-life.core
  (:require
   [ring.util.response :as resp]
   [compojure.route :as route]
   [ring.adapter.jetty :as jetty])
  (:use
   [ring.middleware.multipart-params :only [wrap-multipart-params]]
   [ring.util.response :only [header]]
   [compojure.core :only [context ANY routes defroutes]]
   [compojure.handler :only [api]]))

  (defn assemble-routes []
    (->
     (routes
        (ANY "/" [] (resp/redirect "/index.html"))

        (route/resources "/"))))

  (def handler
    (-> (assemble-routes))

  (defn start [options]
    (jetty/run-jetty #'handler (assoc options :join? false)))

  (defn -main
    ([port]
       (start {:port (Integer/parseInt port)}))
    ([]
       (-main "3000")))

当我运行lein ring server时,我得到一个带有以下堆栈跟踪的java.lang.NullPointerException

  

reload.clj:18 ring.middleware.reload / wrap-reload [fn]   stacktrace.clj:17 ring.middleware.stacktrace / wrap-stacktrace-log [fn]   stacktrace.clj:80 ring.middleware.stacktrace / wrap-stacktrace-web [fn]   jetty.clj:18 ring.adapter.jetty / proxy-handler [fn](未知   来源)ring.adapter.jetty.proxy $ org.eclipse.jetty.server.handler.AbstractHandler $ 0.handle   HandlerWrapper.java:116 org.eclipse.jetty.server.handler.HandlerWrapper.handle   Server.java:363 org.eclipse.jetty.server.Server.handle   AbstractHttpConnection.java:483 org.eclipse.jetty.server.AbstractHttpConnection.handleRequest   AbstractHttpConnection.java:920 org.eclipse.jetty.server.AbstractHttpConnection.headerComplete   AbstractHttpConnection.java:982 org.eclipse.jetty.server.AbstractHttpConnection $ RequestHandler.headerComplete   HttpParser.java:635 org.eclipse.jetty.http.HttpParser.parseNext   HttpParser.java:235 org.eclipse.jetty.http.HttpParser.parseAvailable   AsyncHttpConnection.java:82 org.eclipse.jetty.server.AsyncHttpConnection.handle   SelectChannelEndPoint.java:628 org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle   SelectChannelEndPoint.java:52 org.eclipse.jetty.io.nio.SelectChannelEndPoint $ 1.run   QueuedThreadPool.java:608 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob   QueuedThreadPool.java:543 org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run   Thread.java:744 java.lang.Thread.run

2 个答案:

答案 0 :(得分:1)

我认为如果你的处理函数得到请求参数会更好。

答案 1 :(得分:0)

你能尝试改变这样的依赖吗?这些版本和以下配置完全适用于我:(包括重新加载)

(defproject ..........
 :dependencies [[org.clojure/clojure "1.5.1"]
             [liberator "0.11.0"]
             [ring/ring-core "1.1.8"]
             [ring/ring-jetty-adapter "1.1.8"]
             [compojure "1.1.3"]]
 :main game-of-life.core
 :min-lein-version "2.0.0"
 :plugins [[lein-ring "0.8.10"]]
 :ring {:handler game-of-life.core/handler})

另外,处理程序应该是

(def handler
(-> (assemble-routes)))