119.2. Groovy Shell のカスタマイズ
カスタムの GroovyShell
インスタンスを Groovy 式で使用する必要がある場合があります。カスタムの GroovyShell
を提供するには、 org.apache.camel.language.groovy.GroovyShellFactory
SPI インターフェースの実装を Camel レジストリーに追加します。たとえば、以下の Bean を Spring コンテキストに追加した後
public class CustomGroovyShellFactory implements GroovyShellFactory { public GroovyShell createGroovyShell(Exchange exchange) { ImportCustomizer importCustomizer = new ImportCustomizer(); importCustomizer.addStaticStars("com.example.Utils"); CompilerConfiguration configuration = new CompilerConfiguration(); configuration.addCompilationCustomizers(importCustomizer); return new GroovyShell(configuration); } }
…Camel は、デフォルトのインスタンスではなく、カスタムの GroovyShell インスタンス(カスタムの静的インポートを含む)を使用します。