我开始使用带有mongodb(带有 monger 库)的Clojure luminus 框架进行开发。很难理解如何实现库来启动数据库连接。mount
我发现代码应该放handler.clj
'sinit
函数。
但我不知道如何告诉 mount 启动数据库连接。
请你帮我一把好吗?
这里是我的开发 config.clj
(ns vippro.config
(:require [selmer.parser :as parser]
[clojure.tools.logging :as log]
[vippro.dev-middleware :refer [wrap-dev]]
))
(def defaults
{:init
(fn []
(parser/cache-off!)
(log/info "\n-=[vippro started successfully using the development profile]=-"))
:middleware wrap-dev})
和 inhandler.clj
的init
函数
(defn init
"init will be called once when
app is deployed as a servlet on
an app server such as Tomcat
put any initialization code here"
[]
(when-let [config (:log-config env)]
(org.apache.log4j.PropertyConfigurator/configure config))
(doseq [component (:started (mount/start))]
(log/info component "started"))
((:init defaults)))
我的主要问题是我应该如何以init
正确的方式调用这个函数
(defn connect! []
;; Tries to get the Mongo URI from the environment variable
(reset! db (-> (:database-url env) mg/connect-via-uri :db)))