【发布时间】:2013-04-05 16:26:35
【问题描述】:
我正在关注 this example 在 Clojure 中使用 ring 和 jetty 创建一个简单的 Web 服务。
我的 project.clj 中有这个:
(defproject ws-example "0.0.1"
:description "REST datastore interface."
:dependencies
[[org.clojure/clojure "1.5.1"]
[ring/ring-jetty-adapter "0.2.5"]
[ring-json-params "0.1.0"]
[compojure "0.4.0"]
[clj-json "0.5.3"]]
:dev-dependencies
[[lein-run "1.0.0-SNAPSHOT"]])
这在 script/run.clj 中
(use 'ring.adapter.jetty)
(require '[ws-example.web :as web])
(run-jetty #'web/app {:port 8080})
这个在 src/ws_example/web.clj
(ns ws-example.web
(:use compojure.core)
(:use ring.middleware.json-params)
(:require [clj-json.core :as json]))
(defn json-response [data & [status]]
{:status (or status 200)
:headers {"Content-Type" "application/json"}
:body (json/generate-string data)})
(defroutes handler
(GET "/" []
(json-response {"hello" "world"}))
(PUT "/" [name]
(json-response {"hello" name})))
(def app
(-> handler
wrap-json-params))
但是,当我执行时:
lein run script/run.clj
我收到此错误:
No :main namespace specified in project.clj.
为什么会出现这种情况以及如何解决?
【问题讨论】:
-
您链接到的教程使用 Leiningen 1.x - 您可能应该使用 lein2。
-
如果我能找到一个自学习以来就有效的教程,那就太好了。有什么建议么?我想在 Clojure 中创建一个 Web 服务
标签: clojure jetty leiningen ring