使用(in-ns)在文件之间共享名称空间时出错

问题描述 投票:0回答:1

我正在所有环形路由之间共享一个名称空间,以便将每个路由保留在其自己的文件中,因此我有一个文件routes/core.clj,其中包含:

(ns test-proxy.routes.core)
;; Some utility functions

然后我像这样启动每个路由处理程序文件:

(in-ns 'test-proxy.routes.core)
;; rest of the code

当我启动服务器时,它运行良好。

但是当我更改任何文件并在浏览器中重新加载页面时,出现以下错误:

Caused by: java.lang.Exception: Found lib name 'test-proxy.routes.core' 
containing period with prefix 'quote'.  lib names inside prefix lists 
must not contain periods

如果我手动重新启动服务器(lein ring server),所有操作将再次按预期工作,但是一旦我在代码库中进行了另一次更改,它就会失败,并出现相同的错误。它看起来确实与我使用命名空间的方式有关,但是让我知道的是,当我重新启动服务器时,它可以正常工作。

如果我像错误提示那样将名称空间取消引用为(in-ns test-proxy.routes.core),则服务器甚至无法启动:

Syntax error (ClassNotFoundException) compiling at (diplomat/routes/docs.clj:1:1).
test-proxy.routes.core

我在所有环形路由之间共享一个名称空间,以便将每个路由保留在自己的文件中,所以我有一个文件route / core.clj,其中包含:(ns test-proxy.routes.core);;一些实用程序功能...

clojure namespaces ring
1个回答
0
投票

in-ns仅用于REPL时。

© www.soinside.com 2019 - 2024. All rights reserved.