(Quick Reference)

6 Spring Beans For Namespaces

Version: 2.0.0.RC4

6 Spring Beans For Namespaces

The plugin can create Spring beans that provide access to Clojure functions. Each function namespace can be associated with a different Spring bean.

Function namespaces are associated with Spring bean names that are defined in application.yml. Key value pairs under grails.clojure.namespaceBeans associate function namespaces with Spring bean names.

;; src/main/clj/mathematics.clj
(ns math)

(def doit [] ;; doit code here )

;; src/main/clj/reporting.clj
(ns report)

(def doit [] ;; doit code here )

# grails-app/conf/application.yml

grails: clojure: namespaceBeans: math: mathHelper report: reportHelper

The plugin will create beans named mathHelper and reportHelper which are associated with the math and report namespaces respectively.

// grails-app/controllers/demo/DemoController.groovy
package demo

class DemoController { def mathHelper def reportHelper

def someAction() { // this will invoke the doit function in the math namespace mathHelper.doit()

// … }

def someOtherAction() { // this will invoke the doit function in the report namespace reportHelper.doit()

// … }

}