我想use会这样做,但似乎在当前命名空间中创建的映射不公开.这是我想要实现的一个例子:
(ns my-ns
(:use [another-ns :only (another-fct)]))
(defn my-fct
[]
(another-fct 123)) ; this works fine
Run Code Online (Sandbox Code Playgroud)
然后我有另一个这样的命名空间:
(ns my-ns-2
(:require [my-ns :as my]))
(defn my-fct-2
[]
(my/another-fct 456)) ; this doesn't work
Run Code Online (Sandbox Code Playgroud)
我想这样做是因为它another-ns是一个访问数据库的库.我想在单个命名空间(my-ns)中隔离对该库的所有调用,这样所有与数据库相关的函数都将在单个命名空间中隔离,并且如果需要,更容易切换到另一个数据库.
这个库的一些功能对我来说很好,但我想增加其他功能.假设读取函数很好,但我想通过一些验证来扩充写入函数.
到目前为止,我看到的唯一方法是将所有映射手动编码,my-ns即使对于我没有增加的功能也是如此.
我的命名空间声明如下所示:
(ns test.foo
(:use
[clj-http.client :only (get) :as client]
[net.cgrand.enlive-html :only (select) :as html]))
Run Code Online (Sandbox Code Playgroud)
它在REPL中工作正常,这是我第一次使用它.然后,当我修改代码并在REPL中尝试以下内容时:
(use :reload 'test.foo)
Run Code Online (Sandbox Code Playgroud)
我明白了:
java.lang.IllegalStateException: get already refers to: #'clj-http.client/get in namespace: test.foo (foo.clj:1)
Run Code Online (Sandbox Code Playgroud)
我在逆时针方向的窗户上,也尝试了leiningen(lein repl).
我想将函数的var-args发送到宏,仍然作为var-args.这是我的代码:
(defmacro test-macro
[& args]
`(println (str "count=" ~(count args) "; args=" ~@args)))
(defn test-fn-calling-macro
[& args]
(test-macro args))
Run Code Online (Sandbox Code Playgroud)
输出(test-macro "a" "b" "c")是我想要的:count=3; args=abc
输出(test-fn-calling-macro "a" "b" "c")是:count=1; args=("a" "b" "c")因为args作为单个参数发送到宏.如何在我的函数中展开这个args以便用3个参数调用宏?
我想我只是错过了一个简单的核心功能,但我无法找到它.谢谢
编辑2 - 我的"真实"代码,如下面的编辑部分所示,不是使用此技术的有效情况.
正如@Brian所指出的,宏xml-to-cass可以用这样的函数替换:
(defn xml-to-cass
[zipper table key attr & path]
(doseq [v (apply zf/xml-> zipper path)] (cass/set-attr! table key attr v)))
Run Code Online (Sandbox Code Playgroud)
编辑 - 以下部分超出了我原来的问题,但欢迎任何见解
上面的代码是我能找到的最简单的代码来查明我的问题.我的真实代码处理clj-cassandra和zip-filter.它也可能看起来过度工程,但它只是一个玩具项目,我正在尝试同时学习这门语言.
我想解析mlb.com上的一些XML,并将找到的值插入到cassandra数据库中.这是我的代码及其背后的思想.
第1步 - 功能正常,但包含代码重复
(ns stats.importer
(:require
[clojure.xml :as xml]
[clojure.zip :as …Run Code Online (Sandbox Code Playgroud) 我有一个使用Spring 2.5和Hibernate 3的应用程序.
有一个带有表示层,服务层和DAO层的Web应用程序,以及一些共享相同服务和DAO层的Quartz作业.
使用@Transactional注释在不同的层中初始化事务,如下所示:

它引发了我在这里描述的一个问题:使用Spring 2.5从外部事务控制内部事务设置
我读了一些关于如何设置事务以将Spring和Hibernate连接在一起的内容.看起来推荐的方法是初始化服务层中的事务.
我不喜欢的是大多数事务的存在只是因为它们是hibernate正常工作所必需的.
当我真的需要一个调用多种服务方法的作业的事务时,似乎我没有选择继续从作业初始化事务.因此,将@Transactional注释从DAO移动到服务似乎没有任何区别.
您如何建议为此类应用程序设置事务?
我有一个父项目,有5个孩子,彼此之间也有依赖关系.我<parent>在子<module>节点pom.xml中使用了inheritence 元素,在父节点中使用了元素的聚合.
我的父母pom看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.domain</groupId>
<artifactId>Parent</artifactId>
<packaging>pom</packaging>
<version>RELEASE</version>
<name>Parent</name>
<modules>
<module>../Child1</module>
<module>../Child2</module>
<module>../Child3</module>
<module>../Child4</module>
<module>../Child5</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.domain</groupId>
<artifactId>Child1</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.domain</groupId>
<artifactId>Child2</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
Run Code Online (Sandbox Code Playgroud)
Child3 pom看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.domain</groupId>
<artifactId>Child3</artifactId>
<name>Child3</name>
<packaging>war</packaging>
<parent>
<artifactId>Parent</artifactId>
<groupId>com.domain</groupId>
<version>RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>com.domain</groupId>
<artifactId>Child1</artifactId>
</dependency>
<dependency>
<groupId>com.domain</groupId>
<artifactId>Child2</artifactId>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
当我mvn install在Parent或Child1上运行时,一切正常.但是当我在Child3上运行它时,我得到以下错误:
[INFO] Failed to resolve artifact.
Missing:
----------
1) …Run Code Online (Sandbox Code Playgroud) 我有一个使用Maven 2构建的应用程序,它具有来自SpringSource Enterprise Bundle Repository和Maven2公共存储库的重复依赖项.幸运的是,他们有相同的版本,但我仍然想清理重复.
我应该支持Spring存储库还是Maven?
我的项目经常使用Spring(核心,Web流,安全性),所以我倾向于说我应该使用Spring repo,但我不需要我的jar文件符合OSGi,而且长前缀的名字让我烦恼了一下.
重复示例:
com.springsource.org.apache.commons.logging 和 commons-logging
org.springframework.core 和 spring-core
clojure ×3
maven-2 ×2
spring ×2
aggregation ×1
hibernate ×1
inheritance ×1
jobs ×1
namespaces ×1
repository ×1
transactions ×1