126.3. Groovy Shell のカスタマイズ

Groovy 式でカスタム GroovyShell インスタンスを使用する必要がある場合があります。カスタム 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 インスタンス (カスタムの静的インポートを含む) を使用します。