gpt4 book ai didi

clojure - 莱因环 uberjar

转载 作者:行者123 更新时间:2023-12-01 23:56:53 25 4
gpt4 key购买 nike

我用 Clojure 构建了一个非常简单的网络应用程序(事实上,我遵循了一个教程)。 project.clj 文件如下所示:

(defproject webdev "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[ring "1.2.2"]
[hiccup "1.0.5"]
[compojure "1.1.6"]
[org.clojure/java.jdbc "0.3.3"]
[postgresql/postgresql "9.1-901.jdbc4"]]

:plugins [[lein-ring "0.8.10"]]

:ring {:handler (webdev.core/-main)
:port 8000}

:uberjar-name "webdev.jar"

:main webdev.core

:aot [webdev.core]

:profiles {:dev
{:main webdev.core/-dev-main}})

我的主要 webdev/core.clj 的相关部分如下所示:

(defroutes routes
(GET "/about" [] about)
(ANY "/request" [] handle-dump)

(GET "/items" [] handle-index-items)
(POST "/items" [] handle-create-item)
(DELETE "/items/:item-id" [] handle-delete-item)
(PUT "/items/:item-id" [] handle-update-item)

(not-found "Page not found."))


(defn wrap-db [hndlr]
(fn [req]
(hndlr (assoc req :webdev/db db))))

(defn wrap-server-header [hndlr]
(fn [req]
(hndlr (assoc req :webdev/db db))))

(defn wrap-server-response [hndlr]
(fn [req]
(let [response (hndlr req)]
(assoc-in response [:headers "Server:"] "my-server"))))


(def sim-methods {"PUT" :put
"DELETE" :delete})

(defn wrap-simulated-methods [hndlr]
(fn [req]
(if-let [method (and (= :post (:request-method req))
(sim-methods (get-in req [:params "_method"])))]
(hndlr (assoc req :request-method method))
(hndlr req))))

(def app
(wrap-file-info
(wrap-resource
(wrap-server-response
(wrap-db
(wrap-params
(wrap-simulated-methods routes)))) "static")))

(defn -main [& [port]]
(items/create-table db)
(jetty/run-jetty #'app
{:port (if port (Integer/parseInt port)
(Integer/parseInt (System/getenv "PORT")))}))

(defn -dev-main [port]
(items/create-table db)
(jetty/run-jetty (wrap-reload #'app) {:port (Integer. port)}))

....

如果我在我的项目上运行 Lein ring serverLein ring uberjar 我会收到以下错误:

java.lang.ClassCastException: clojure.lang.PersistentList 
cannot be cast to clojure.lang.Named

如果我运行 Lein run 8000。它工作正常,我可以浏览到 localhost:8000

我的 Leiningen 版本是:

Leiningen 2.3.4 on Java 1.6.0_26 Java HotSpot(TM) 64-Bit Server VM

谁知道怎么回事?

问候,西蒙

最佳答案

看起来不对。

 :ring {:handler (webdev.core/-main)
:port 8000}

(webdev.core/-main) 意味着运行您的主函数并将主函数的结果作为处理程序委托(delegate)给环插件。

在使用 lein ring 时尝试使用更像这样的东西......

 :ring {:handler webdev.core/app
:port 8000}

关于clojure - 莱因环 uberjar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23222145/

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