44.7. Groovy Shell のカスタマイズ
非常に特殊なユースケースでは、Groovy 式でカスタム GroovyShell インスタンスを使用する必要がある場合があります。カスタム GroovyShell を指定するには、org.apache.camel.language.groovy.GroovyShellFactory SPI インターフェイスの実装を Camel レジストリーに追加します。
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 インスタンス (カスタムの静的インポートを含む) を使用します。