-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Michael Ottati opened SPR-8625 and commented
In attempting to refactor a bean from a statically compiled groovy script to a dynamically compiled one, I made the following change to my context.xml.
ORIGINAL
<bean id="routeBuilder" depends-on="routeModelExtender"
class="org.openehealth.tutorial.SampleRouteBuilder">
</bean>
MODIFIED
<lang:groovy id="routeBuilder" depends-on="routeModelExtender"
script-source="classpath:DynamicGroovyRouteBuilder.groovy">
</lang:groovy>
The code contained in DynamicGroovyRouteBuilder was an exact copy of the groovy script that was statically compiled. Upon testing this new configuration, it failed. The failure was at first cryptic however upon further examination I determined that the root cause of the failure was due to the fact that the bean my groovy script was dependent upon had not been instantiated.
I was able to correct the problem by declaring the dependency in a slightly different way. Instead of relying on the "depends-on" attribute, I added a property element to the dynamic language bean which referenced the bean I depended upon. The resulting definition did work.
WORKING
<lang:groovy id="routeBuilder"
script-source="classpath:DynamicGroovyRouteBuilder.groovy">
<lang:property name="routeModelExtender" ref="routeModelExtender"/>
</lang:groovy>
I am attaching a simple project that demonstrates the problem. Within the test case there are three tests:
StaticTest Original working configuration with statically compiled groovy
DynamicDependsOnTest Failure case
DynamicRefTest Fix described above.
When these tests are run individually they work as described. When the tests are run together, for instance when running them with the mvn "test" goal they fail. The failure is described in this thread:
I have attached a test case that demonstrates the bug.
Affects: 3.0.5
Attachments:
- SpringDependencyBug.tgz (24.32 kB)
Referenced from: commits spring-attic/spring-framework-issues@b5326cc