126.2. Groovy Shell 사용자 정의

때때로 Groovy expressions에서 사용자 정의 GroovyShell 인스턴스를 사용해야 할 수도 있습니다. 사용자 지정 GroovyShell 을 제공하려면 Camel 레지스트리에 org.apache.camel.language.groovy.GroovyShellFactory SPI 인터페이스를 구현합니다. 예를 들어 Spring context…​에 다음 빈을 추가한 후

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 인스턴스(사용자 지정 정적 가져오기 포함)를 사용합니다.