|
I will prepare a zip file which contains my workaround for this scope problem and upload here. In order to allow script bean has scope, you need to change the following file: In the ScriptBeanDefinitionParser java file, there is a method called parseInternal where you should find a RootBeanDefinition object which is used to control the scope of the script bean. In order to control the script bean scope, the above code should modify to: // suppose you have already get the script scope value in above and Find the following section in spring-lang-2.0.xsd: Then add a new xsd attribute script-scope after the above script-source attribute. For example: ... Rebuild the spring.jar and with the update xsd file. You can add the "script-scope" attribute to groovy bean definition like normal bean. If you found any problem, please alert me. So far it works fine in my application. But I am still afraid of any hidden problem. cheers This is a quick patch against 2.0.2 to enable 'prototype' and 'singleton' script beans. It adds 'script-scope' to the lang:script_lang tag. The acceptable values are 'prototype' and 'singleton'. If no script-scope is present beans are singleton. I have not tested this extensively. I also have no experience with the Spring tests. If someone could provide some advice I'll write some tests. This patch would probably also work against HEAD, but I had some issues with getting that working, and had the 2.0.2 source. Dear Mark Thanks a lot for your patch. I have ported my junit test programs for 2.0.3 to 2.0.2 and your patch passes all junit test programs for Groovy. Since there are some problems for Beanshell and JRuby in 2.0.2, I have skipped the test for Beanshell and JRuby. You have mentioned a "HEAD" problem in your comment. Would you mind tell me what is "HEAD" problem? I have 2 concerns about the solution: cheers Thanks for pointing this out! While we do support custom script scopes at the ScriptFactory level already (as of 2.0.3), this is not exposed in the "lang" namespace yet. Hence I've added a "scope" attribute to all script tags in the "lang" namespace, allowing for non-singleton script objects defined in that convenient style, analogous to the "scope" attribute in a standard bean definition. This should be available in tonight's 2.0.4 snapshot. Please give it a try and let me know whether it works for you! Juergen |
|||||||||||||||||||||||||||||||||||||||||||||||
I've spent the last several days digging into this. If I got some guidance I think I might be able to help with this issue.
I'm interested, because I'm trying to move my actions for Struts 2 to Groovy. They need to have prototype scope to make it work though.
Thanks,
Mark