A bit of an update (if anybody is even following this!).

I've pushed some more changes to my fork (
https://github.com/Orkie/spring-framework/tree/SPR-11530).

I've added the attribute 'immutable-properties' which tells the dynamic 
language post processor to intercept/resolve the properties and pass them 
into the factory code before the script is executed. These are then bound 
to a map which you reference with *spring-bindings*. I'm a lot happier with 
this approach from a Clojure point of view, but I'm not sure how elegant it 
is in terms of how the Spring code is written: there is essentially one 
large, hand-written DOM parser, and it wasn't designed to be extended like 
this. To add a new tag which behaves broadly the same way as property 
(which is what I want) would be a huge amount of work, and I'm also having 
to fiddle with the bean factory slightly to allow it to resolve 
properties-like objects without doing all the other property stuff (setting 
internal spring state, calling setters etc.). I'm going to try and get some 
feedback from one of the Spring guys to see what they think.

As it stands, you would now to something like this..

Spring XML context:
<lang:clojure id="calculator" immutable-properties="true">
<lang:inline-script>
(reify org.springframework.scripting.Calculator
(add [this x y]
(+ x y)))
</lang:inline-script>
</lang:clojure>
 <lang:clojure id="messenger" 
script-source="classpath:org/springframework/scripting/clojure/Messenger.clj" 
immutable-properties="true">
<lang:property name="message" value="Hello World!"/>
<lang:property name="thecalc" ref="calculator" />
</lang:clojure>

classpath:org/springframework/scripting/clojure/Messenger.clj:
(ns Messenger)

(def my-calculator (get *spring-bindings* "thecalc"))
(def the-message (get *spring-bindings* "message"))

(reify org.springframework.scripting.Messenger
(getMessage [this] (str the-message (.add my-calculator 4 9))))



On Saturday, 8 March 2014 16:10:56 UTC, Adan Scotney wrote:
>
> Hi,
>
> I have a Java project which uses Spring to wire together various services, 
> and the only way I've managed to find to integrate Clojure services 
> (without using gen-class) is to have something resembling the 
> MethodInvokingFactoryBean, or to manually write a wrapper which calls out 
> to Clojure. Since everything else is instantiated in Spring, it'd be a lot 
> nicer to have this sort of thing all in one place than scattered around, 
> and Spring has support for creating beans with dynamic languages, but 
> Clojure isn't currently one of those supported!
>
> I've got most of the way towards having a patch which works, however I'm 
> not entirely sure about the approach. Spring doesn't let beans constructed 
> this way have constructor-injection, only by using setters. For now, I've 
> abused the name attribute on property to give the fully qualified name of a 
> function which binds a var with the value of the 'property'. This isn't 
> ideal, but I can't think of another way of approaching this without 
> defining a load of types on the fly and giving setter methods for those 
> (maybe somebody else can?).
>
> JIRA relating to the patch (with a quick explanation of why I've taken 
> this approach): https://jira.spring.io/browse/SPR-11530
> Dynamic language doc: 
> http://docs.spring.io/spring/docs/4.0.3.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#dynamic-language
>
> Of particular interest in seeing quickly how it is used at present (since 
> I doubt anybody else wants to go through the trouble of getting the whole 
> thing set up in Eclipse..), may be..
>
> https://github.com/Orkie/spring-framework/blob/SPR-11530/spring-context/src/test/java/org/springframework/scripting/clojure/clojureContext.xml
>
> https://github.com/Orkie/spring-framework/blob/SPR-11530/spring-context/src/test/java/org/springframework/scripting/clojure/Messenger.clj
>
> Any suggestions would be appreciated,
> Adan
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to