下面是关于如何使用compojure的这教程,除了这个例外,我遇到了一个死胡同:
lein ring server
2022-08-09 23:19:55.538:INFO::main: Logging initialized @921ms
WARN clojure.tools.logging not found on classpath, compojure.api logging to console.
Exception in thread "main" java.lang.RuntimeException: Map literal must contain an even number of forms, compiling:(ring_test/core.clj:16:16)除了将我的路由更改为测试路径外,我保持了与教程相同的所有内容:
(ns ring-test.core
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]))
(def app
(api
{:swagger
{:ui "/"
:spec "swagger.json"
:data {:info {:tile "Test"}
:tags [{:name "api"}]}}
(context "/api" []
:tags ["api"]
(GET "/test" []
:body ["test"]
(ok)))}))并更新了project.clj中的一些版本
(defproject ring-test "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.8.0"]
[metosin/compojure-api "2.0.0-alpha28"]]
:ring {:handler ring-test.core/app}
:profiles {:dev
{:plugins [[lein-ring "0.12.5"]]
:dependencies [[javax.servlet/servlet-api "2.5"]]}})如果有人能帮我解决这个问题,那就太棒了!
发布于 2022-08-10 02:49:53
在本教程中,(上下文.)在地图外。
(def app
(api {:swagger
{:ui "/"
:spec "/swagger.json"
:data {:info {:title "Account Service"}
:tags [{:name "api"}]}}} ;; END-OF-MAP HERE
;; This from is _NOT_ in the map
(context "/api" []
:tags ["api"]
(POST "/account" []
:body [account (describe NewAccount "new account")]
(ok))
(POST "/transfer" []
:body [transfer (describe NewTransfer "new transfer")]
(ok)))))问题是在你的版本中,你移动(上下文.)在这张地图里。
(def app
(api {:swagger {:ui "/"
:spec "swagger.json"
:data {:info {:tile "Test"}
:tags [{:name "api"}]}}
;; This from is in the map
(context "/api" []
:tags ["api"]
(GET "/test" []
:body ["test"]
(ok)))
} ;; END-OF-MAP HERE
))您可以通过移动(上下文.)来修复这个问题。到地图外,如本教程所示。
https://stackoverflow.com/questions/73298788
复制相似问题