Clojure库中是否有"assoc-if"函数?即,如果值是真实的,则使用给定的键值更新地图.我试图找到这种效果的东西,但缺乏.
(defn assoc-if
[m key value]
(if value (assoc m key value) m))
Run Code Online (Sandbox Code Playgroud) 我在Spring(版本2.5.6)中使用切入点定义时遇到了问题.我试图拦截对类的所有方法调用,除了给定的方法(下面的例子中的someMethod).
<aop:config>
<aop:advisor
pointcut="execution(* x.y.z.ClassName.*(..)) AND NOT
execution(* x.y.x.ClassName.someMethod(..))"
/>
</aop:config>
Run Code Online (Sandbox Code Playgroud)
但是,也会为someMethod调用拦截器.
然后我尝试了这个:
<aop:config>
<aop:advisor
pointcut="execution(* x.y.z.ClassName.(* AND NOT someMethod)(..)) )"
/>
</aop:config>
Run Code Online (Sandbox Code Playgroud)
但这不能编译,因为它不是有效的语法(我得到一个BeanCreationException).
任何人都可以提供任何建议吗?
我已经挖掘了Jetty文档试图找出如何正确配置嵌入式Jetty以优雅地关闭,但我发现它缺乏.
随后使用文档中的示例setStopAtShutdown(true)
.但是,没有JavaDoc或解释为什么要这样做.据我所知,默认值设置为false.
此外,该setGracefulShutdown()
方法似乎改为setStopTimeout()
,但这也没有记录.
所以这些是我的问题:
编辑:经过一些试验和错误; 发现如果你想让Jetty向任何侦听器发出关闭事件,例如Spring的ContextLoaderListener,则需要setStopAtShutdown(true).
在没有重新启动应用程序的情况下更改后,Grails中是否有一种方法可以运行BootStrap.groovy的内容?
说我有以下规格:
(s/def :person/age number?)
(s/def :person/name string?)
(s/def ::person (s/keys :req [:person/name :person/age]))
Run Code Online (Sandbox Code Playgroud)
然后我从Datomic中获取一个实体:
(def person-entity (d/entity (d/db conn) [:person/name "Mr entity"]))
Run Code Online (Sandbox Code Playgroud)
如果我尝试检查与规范的一致性,它会失败,因为实体不是地图:
(s/explain ::person person-entity)
val: #:db{:id 17592186069950} fails spec: :some-ns/person predicate: map?
Run Code Online (Sandbox Code Playgroud)
我的应用程序具有将实体作为参数的功能,并且希望避免为了使规范工具在开发中工作而必须将实体统一到各地的映射.
我应该如何通过规范验证实体?
我有基于compojure的应用程序,我需要解析一个请求并检索可以是数字的参数.我希望能够在实际处理请求之前验证参数是否存在以及它们是否为数字.这是我到目前为止:
(defn get-int [str]
"Returns nil if str is not a number"
(try (Integer/parseInt str)
(catch NumberFormatException _)))
(defn some-request [request]
(let [some-number (get-int (get-in request [:route-params :some-number])
other-number (get-int (get-in request [:route-params :other-number])]
(if (every? identity [some-number other-number])
(process-the-request)
(bad-request "The request was malformed")))
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来进行字符串 - >数字转换?
有没有更好的方法来进行请求验证?
有没有一种简单的方法可以在ClojureScript中列出JavaScript对象的属性和功能?
我尝试过以下方法:
(keys (js->clj (.getContext canvas "2d")))
Run Code Online (Sandbox Code Playgroud)
但是这会引发以下错误:
ExceptionInfo #<Error: [object CanvasRenderingContext2D] is not ISeqable> clojure.core/ex-info (core.clj:4591)
Run Code Online (Sandbox Code Playgroud) 在Kafka流应用程序上启用一次完全处理后,日志中会出现以下错误:
ERROR o.a.k.s.p.internals.StreamTask - task [0_0] Failed to close producer
due to the following error:
org.apache.kafka.streams.errors.StreamsException: task [0_0] Abort
sending since an error caught with a previous record (key 222222 value
some-value timestamp 1519200902670) to topic exactly-once-test-topic-
v2 due to This exception is raised by the broker if it could not
locate the producer metadata associated with the producerId in
question. This could happen if, for instance, the producer's records
were deleted because their retention time had elapsed. Once the …
Run Code Online (Sandbox Code Playgroud) 在tools.logging的最新版本(0.2.4)中,当使用(error some-exception)进行日志记录时,仅记录异常消息.我依赖于在记录异常时打印堆栈跟踪.将异常打印到stderr或stdout不是一种选择.
据我所知,在源代码中,(error ...)确实将异常作为第一个参数.
(log/error throwable error-message)
Run Code Online (Sandbox Code Playgroud)
记录时,我可以做些什么来包含堆栈跟踪?
我有一个地图列表,其中每个键与一个字符串列表相关联.
我想将这些字符串列表中的每一个转换为集合.
(def list-of-maps-of-lists '({:a ["abc"]} {:a ["abc"]} {:a ["def"]} {:x ["xyz"]} {:x ["xx"]}))
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我最好的尝试:
(flatten (map (fn [amap] (for [[k v] amap] {k (set v)})) list-of-maps-of-lists))
=> ({:a #{"abc"}} {:a #{"abc"}} {:a #{"def"}} {:x #{"xyz"}} {:x #{"xx"}})
Run Code Online (Sandbox Code Playgroud)
这个问题的惯用解决方案是什么?
clojure ×5
aop ×1
apache-kafka ×1
clojure.spec ×1
compojure ×1
datomic ×1
grails ×1
java ×1
jetty ×1
spring ×1
spring-aop ×1