Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Spring Beans in a Clojure Application?

I have a lot of spring beans that enscapsulate existing business logic. Now I am looking to re-use those Spring Beans from within my new Clojure Compojure application. How do I do this ?

What I am looking for is Clojure equivalent of this

Context context = new ClassPathXmlApplicationContext(....);

MyBean mybean = context.get("mybean", MyBean.class)

Is there a Clojure way of doing this ?

like image 276
user193116 Avatar asked Jun 05 '13 01:06

user193116


1 Answers

(let [context (ClassPathXmlApplicationContext. ...)
      mybean  (.get context "mybean" MyBean)]
  ...)

is the Clojure equivalent of your Java code. ... is whatever you want to do next. Or if you want to return mybean as the value of the whole thing (perhaps this will be wrapped in a function):

(let [context (ClassPathXmlApplicationContext. ...)]
  (.get context "mybean" MyBean))

Note the dot at the end of ClassPathXmlApplicationContext.; that's shorthand for new, as in (new ClassPathXmlApplicationContext ...).

like image 105
Michał Marczyk Avatar answered Oct 29 '22 12:10

Michał Marczyk