Spring Boot integration

Spring Boot starter provides the following features:

  • JavascriptRendererSpringConfigurator bean for setting up a new JavascriptRenderer instance.

  • retrieving script source file from an external server using Spring WebClient

To include JS Renderer library in your Spring Boot application add the the following dependency.

build.gradle.kts
dependencies {
    implementation("io.wttech.graal.templating:templating-spring-boot-starter:0.4.0")
}

Maven

pom.xml
<dependencies>
  <dependency>
    <groupId>io.wttech.graal.templating</groupId>
    <artifactId>templating-spring-boot-starter</artifactId>
    <version>0.4.0</version>
  </dependency>
</dependencies>

The example below shows how to configure renderer to read an external source file.

  @Bean
  JavascriptRenderer javascriptRenderer(JavascriptRendererSpringConfigurator configurator, WebClient webClient) {
    return configurator
        .externalScript(builder -> builder.webClient(webClient).uri(URI.create("http://localhost:3000/bundle.js")).build())
        .buildDevelopment();
  }