In my application context file I have a Groovy "refreshable" bean defined. The bean is defined with an http: prefix (see below). The p开发者_Python百科roblem I'm having is that our web servers do not send the last-modified header, which the refreshable bean requires to determine if the script has been modified.
I need to host the scripts on our web servers, and I can't modify the server config to send the last-modified header. So the only option I can think of is to manually force a refresh by calling some method on the bean.
Is there any way, given the bean below, that I can force a refresh?
<lang:groovy id="messenger" refresh-check-delay="1000"
script-source="http://10.74.192.111/groovy/GroovyMessenger.groovy" />
Could I maybe create a GroovyObjectCustomizer that would add a forceRefresh method?
Thanks
I'd say the problem should be fixed if you replace the standard implementation of the script factory post processor bean.
The explanation would be quite long, and it would be the same idea as
http://www.ibm.com/developerworks/java/library/j-groovierspring1.html
http://www.ibm.com/developerworks/java/library/j-groovierspring2.html
http://www.springone2gx.com/blog/scott_leberknight/2010/10/database_backed_refreshable_beans_with_groovy_and_spring_3
Last link is an addition to the original series in case you are using spring 3 (which i believe should be your case)
In short, you would want a different kind of org.springframework.scripting.ScriptSource
, one that always returns true
when asked if modified. The standard implementation would ask the underlying org.springframework.core.io.Resource
implementation and in your case,
return false
as result of checking the header contents of an http head request. You can do this with a custom org.springframework.scripting.support.ScriptFactoryPostProcessor
.
But again, check the articles there. They include a highly detailed explanation of the changes required.
精彩评论