1

I am using the dynamic language support in spring for Groovy to setup a groovy class that implements one of my interfaces in a .groovy file. In the spring docs the recommended approach to configure a dynamic language bean is in the XML as follows:

<lang:groovy id="messenger" script-source="classpath:Messenger.groovy">
<lang:property name="message" value="I Can Do The Frug" />
</lang:groovy>

I can get this to work, but I was wondering is there a way to configure a dynamic language bean through annotation instead of through XML. The scenario I am thinking of is if I created a new class implementation for an interface that is currently not configured in the XML. I would have to stop the container in order to add the entry to the spring XML. This defeats the purpose of dynamic language support in that I want to be able to hot deploy the new service implementation.

So, my question is, is there an equivalent annotation approach to configure lang:groovy as shown above in XML that I can include in my .groovy file or elsewhere that will force spring to scan and compile the .groovy file?

Ro Hail
  • 21
  • 3
  • You can always add the `@Component` annotation to your groovy class. However it will not be detected unless you restart the container just as you have to add it in xml. – M. Deinum Jan 01 '15 at 07:51
  • I don't think this works in the case of dynamic language beans. for example, how do you specify the delay refresh check attribute in that case, which is one of the attributes supported in lang:groovy tag when configuring through XML – Ro Hail Jan 03 '15 at 21:18
  • Correct. With `@Component` you kind of loose the dynamic features. But what you want cannot be achieved (afaik) in either way xml or annotations as the container will simply not detect new beans regardless the way they are defined. – M. Deinum Jan 04 '15 at 07:56
  • possible duplicate of [Using Spring Dynamic Languages Support from Java Configuration](http://stackoverflow.com/questions/26208020/using-spring-dynamic-languages-support-from-java-configuration) – Nick Grealy Aug 24 '15 at 07:20

0 Answers0