From 8e5244ac3dd218cceef42ee5fe959f932fe875e4 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Thu, 23 Jul 2015 23:39:02 +0200 Subject: [PATCH] Polish script templating documentation --- .../view/script/ScriptTemplateConfigurer.java | 14 +++++++------- .../web/servlet/config/spring-mvc-4.2.xsd | 4 +++- src/asciidoc/web-view.adoc | 12 +++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateConfigurer.java index efff09f64f..e9714b4836 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateConfigurer.java @@ -26,10 +26,8 @@ import javax.script.ScriptEngine; *
  *
  * // Add the following to an @Configuration class
- *
  * @Bean
  * public ScriptTemplateConfigurer mustacheConfigurer() {
- *
  *    ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
  *    configurer.setEngineName("nashorn");
  *    configurer.setScripts("mustache.js");
@@ -39,9 +37,9 @@ import javax.script.ScriptEngine;
  * }
  * 
* - *

NOTE: It is possible to use non thread-safe script engines and - * templating libraries, like Handlebars or React running on Nashorn, by setting - * the {@link #setSharedEngine sharedEngine} property to {@code false}. + *

NOTE: It is possible to use non thread-safe script engines with + * templating libraries not designed for concurrency, like Handlebars or React running on + * Nashorn, by setting the {@link #setSharedEngine sharedEngine} property to {@code false}. * * @author Sebastien Deleuze * @since 4.2 @@ -102,8 +100,10 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { /** * When set to {@code false}, use thread-local {@link ScriptEngine} instances instead * of one single shared instance. This flag should be set to {@code false} for those - * using non thread-safe script engines and templating libraries, like Handlebars or - * React running on Nashorn for example. + * using non thread-safe script engines with templating libraries not designed for + * concurrency, like Handlebars or React running on Nashorn for example. + * In this case, Java 8u60 or greater is required due to + * this bug. *

When this flag is set to {@code false}, the script engine must be specified using * {@link #setEngineName(String)}. Using {@link #setEngine(ScriptEngine)} is not * possible because multiple instances of the script engine need to be created lazily diff --git a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.2.xsd b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.2.xsd index 554092bea8..a424c3da9e 100644 --- a/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.2.xsd +++ b/spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.2.xsd @@ -1265,7 +1265,9 @@ diff --git a/src/asciidoc/web-view.adoc b/src/asciidoc/web-view.adoc index c9b7a0a06d..2f5f0ab86a 100644 --- a/src/asciidoc/web-view.adoc +++ b/src/asciidoc/web-view.adoc @@ -1489,7 +1489,8 @@ It has been tested with: To be able to use script templates integration, you need to have available in your classpath the script engine: -* http://openjdk.java.net/projects/nashorn/[Nashorn] Javascript engine is provided builtin with Java 8+ +* http://openjdk.java.net/projects/nashorn/[Nashorn] Javascript engine is provided builtin with Java 8+. + Using the latest update release available is highly recommended. * http://docs.oracle.com/javase/7/docs/technotes/guides/scripting/programmer_guide/#jsengine[Rhino] Javascript engine is provided builtin with Java 6 and Java 7. Please notice that using Rhino is not recommended since it does not @@ -1617,11 +1618,20 @@ browser facilities not available in the server-side script engine. configurer.setEngineName("nashorn"); configurer.setScripts("polyfill.js", "handlebars.js", "render.js"); configurer.setRenderFunction("render"); + configurer.setSharedEngine(false); return configurer; } } ---- +[NOTE] +==== +Setting the `sharedEngine` property to `false` is required when using non thread-safe +script engines with templating libraries not designed for concurrency, like Handlebars or +React running on Nashorn for example. In that case, Java 8u60 or greater is required due +to https://bugs.openjdk.java.net/browse/JDK-8076099[this bug]. +==== + `polyfill.js` only defines the `window` object needed by Handlebars to run properly: [source,javascript,indent=0] -- GitLab