Results 1 to 2 of 2

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

Threaded View

  1. #1
    Join Date
    Jun 2012
    Location
    Russia
    Posts
    2

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

    Hi,

    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) {
    System.out.println(calc.getCalcValue());
    Thread.sleep(10000L);
    }
    }
    }


    The spring logger shows that the Spring has detected my groovy bean change, but has not updated the groovy code itself:
    30
    30
    30
    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'
    30



    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.
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •