GroovyScriptFactory supports CompilationCustomizer next to GroovyObjectCustomizer

Issue: SPR-14585
This commit is contained in:
Juergen Hoeller
2016-08-17 00:47:50 +02:00
parent 214c919742
commit 433764d217
4 changed files with 88 additions and 20 deletions

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scripting.groovy;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
/**
* @author Juergen Hoeller
*/
public class MyImportCustomizer extends ImportCustomizer {
public MyImportCustomizer() {
addStarImports("org.springframework.scripting.groovy");
}
}

View File

@@ -2,7 +2,7 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">
@@ -24,7 +24,7 @@
<lang:property name="message" value="Hello World!"/>
</lang:groovy>
<lang:groovy id="calculator" depends-on="messenger" customizer-ref="customizer">
<lang:groovy id="calculator" depends-on="messenger" customizer-ref="groovyObjectCustomizer">
<lang:inline-script>
package org.springframework.scripting.groovy;
import org.springframework.scripting.Calculator
@@ -36,10 +36,8 @@ class GroovyCalculator implements Calculator {
</lang:inline-script>
</lang:groovy>
<lang:groovy id="customizer">
<lang:groovy id="groovyObjectCustomizer" customizer-ref="importCustomizer">
<lang:inline-script><![CDATA[
import org.springframework.scripting.groovy.GroovyObjectCustomizer;
public class TestCustomizer implements GroovyObjectCustomizer {
public void customize(GroovyObject o) {
println "customizing ${o}.."
@@ -48,13 +46,15 @@ public class TestCustomizer implements GroovyObjectCustomizer {
</lang:inline-script>
</lang:groovy>
<bean id="importCustomizer" class="org.springframework.scripting.groovy.MyImportCustomizer"/>
<lang:groovy id="refreshableMessenger" refresh-check-delay="5000"
script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
<lang:property name="message" value="Hello World!"/>
</lang:groovy>
<lang:groovy script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
<lang:property name="message" value="Hello World!"/>
</lang:groovy>
<lang:groovy script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy">
<lang:property name="message" value="Hello World!"/>
</lang:groovy>
</beans>