Announcement Announcement Module
No announcement yet.
<lang:groovy refresh-check-delay="..."/> does not actually refresh Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • <lang:groovy refresh-check-delay="..."/> does not actually refresh


    I have a very simple groovy bean and I am trying to make the Spring reload it at run time when I change the groovy bean's code.
    It does not work for me.

    The groovy bean:
    import my.script.ICalc
    class Calc implements ICalc {
    int getCalcValue() { return 30; }

    I change the code by changing the return value from '30' to some another number.

    The spring config:
    <lang:groovy id="calc" script-source="classpath:Calc.groovy" refresh-check-delay="10" />

    The invoking code:
    public class AppScript {
    public static void main(String[] args) throws InterruptedException {
    ApplicationContext context = new ClassPathXmlApplicationContext("spring-beans.xml");
    ICalc calc = (ICalc)context.getBean("calc");
    for (int ii=0; ii<10; ++ii) {

    The spring logger shows that the Spring has detected my groovy bean change, but has not updated the groovy code itself:
    17:24:06,452 DEBUG main support.DefaultListableBeanFactory:429 - Creating instance of bean 'scriptedObject.calc'
    17:24:06,452 DEBUG main support.DefaultListableBeanFactory:244 - Returning cached instance of singleton bean 'scriptFactory.calc'
    17:24:06,454 DEBUG main support.DefaultListableBeanFactory:457 - Finished creating instance of bean 'scriptedObject.calc'

    In debugger I see that the change is detected and 'AbstractRefreshableTargetSource.refresh(...)' is called, but the actual groovy bean code is not reloaded since it is cached in GroovyClassLoader.sourceCache member.
    It is cached since GroovyCodeSource object is always created with its 'cachable' member = 'true'
    (see GroovyClassLoader.parseClass(...) method).

    I tried spring versions 3.1.0, 3.0.7, and 3.0.1 - all of them show the same behavior.

    Do I make some simple mistake or it's an actual Spring bug?
    Attaching a simple project, the class to run is 'my.script.AppScript', although I think the problem can be easily reproduced in any project.

    Any help would be very appreciated.

  • #2
    Just found the problem, it was a bug in Groovy 1.7.0.
    The problem disappeared when I switched to groovy 1.8.6.