Table of Contents
Dynamic Language Support in Spring
Spring supports the use of scripts. In other words, create a bean in Groovy, Jruby and call it as a normal bean from our application.
However, when I tried to use this feature of Spring, even with the last up-to-date version (3.1.1), many errors arise, due to the lack of proper libraries.
Many forums recall to the use of Maven to download properly these missing jars, but I don't want to use it. Other forums give solutions that are not solutions at all, so I've decided to collect these notes.
java.lang.ClassNotFoundException: org.aopalliance.aop.Advice
You can find this missing class in this sourceforge project:
http://sourceforge.net/projects/aopalliance
However the 'default' file for download is an incorrect one: an alpha version that doesn't work. Look into the files section to get the latest version.
java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
You have to download Groovy.
I made the following:
- Download Groovy (binary release)
- Unzip the file and locate the “embedable” directory in it: it contains a single jar file with all the groovy
- Add it to your project
Location is incorrect also
Here is my working example of my –still very simple– groovy bean:
<lang:groovy id="customField" script-source="classpath:com/supermanhamuerto/nestor/actions/CustomFieldImpl.groovy" scope="prototype"> <lang:property name="message" value="Hello from groovy!!!!"/> </lang:groovy>
If you have put your script into the package “com.supermanhamuerto.nestor.actions”, you must specify the complete path into the script-source
attribute.