下面列出了怎么用org.springframework.web.servlet.view.script.ScriptTemplateConfigurer的API类实例代码及写法,或者点击链接到github查看源代码。
@Bean
public ScriptTemplateConfigurer reactConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("nashorn");
configurer.setScripts("static/polyfill.js",
"static/lib/js/ejs.min.js",
"/META-INF/resources/webjars/react/0.13.1/react.js",
// "/META-INF/resources/webjars/react/0.13.1/JSXTransformer.js",
"static/render.js",
"static/output/comment.js",
"static/output/comment-form.js",
"static/output/comment-list.js");
configurer.setRenderFunction("render");
configurer.setSharedEngine(false);
return configurer;
}
/**
* Register a script template view resolver with an empty default view name prefix and suffix.
* @since 4.2
*/
public UrlBasedViewResolverRegistration scriptTemplate() {
if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
throw new BeanInitializationException("In addition to a script template view resolver " +
"there must also be a single ScriptTemplateConfig bean in this web application context " +
"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
"This bean may be given any name.");
}
ScriptRegistration registration = new ScriptRegistration();
this.viewResolvers.add(registration.getViewResolver());
return registration;
}
@Before
public void setup() {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
context.registerSingleton("tilesConfigurer", TilesConfigurer.class);
context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class);
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
this.registry = new ViewResolverRegistry(new ContentNegotiationManager(), context);
}
/**
* Register a script template view resolver with an empty default view name prefix and suffix.
* @since 4.2
*/
public UrlBasedViewResolverRegistration scriptTemplate() {
if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
throw new BeanInitializationException("In addition to a script template view resolver " +
"there must also be a single ScriptTemplateConfig bean in this web application context " +
"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
"This bean may be given any name.");
}
ScriptRegistration registration = new ScriptRegistration();
this.viewResolvers.add(registration.getViewResolver());
return registration;
}
@Before
public void setup() {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
context.registerSingleton("tilesConfigurer", TilesConfigurer.class);
context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class);
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
this.registry = new ViewResolverRegistry(new ContentNegotiationManager(), context);
}
/**
* Register a script template view resolver with an empty default view name prefix and suffix.
* @since 4.2
*/
public UrlBasedViewResolverRegistration scriptTemplate() {
if (!checkBeanOfType(ScriptTemplateConfigurer.class)) {
throw new BeanInitializationException("In addition to a script template view resolver " +
"there must also be a single ScriptTemplateConfig bean in this web application context " +
"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
"This bean may be given any name.");
}
ScriptRegistration registration = new ScriptRegistration();
this.viewResolvers.add(registration.getViewResolver());
return registration;
}
/**
* Register a script template view resolver with an empty default view name prefix and suffix.
* @since 4.2
*/
public UrlBasedViewResolverRegistration scriptTemplate() {
if (this.applicationContext != null && !hasBeanOfType(ScriptTemplateConfigurer.class)) {
throw new BeanInitializationException("In addition to a script template view resolver " +
"there must also be a single ScriptTemplateConfig bean in this web application context " +
"(or its parent): ScriptTemplateConfigurer is the usual implementation. " +
"This bean may be given any name.");
}
ScriptRegistration registration = new ScriptRegistration();
this.viewResolvers.add(registration.getViewResolver());
return registration;
}
@Before
public void setUp() {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);
context.registerSingleton("velocityConfigurer", VelocityConfigurer.class);
context.registerSingleton("tilesConfigurer", TilesConfigurer.class);
context.registerSingleton("groovyMarkupConfigurer", GroovyMarkupConfigurer.class);
context.registerSingleton("scriptTemplateConfigurer", ScriptTemplateConfigurer.class);
this.registry = new ViewResolverRegistry();
this.registry.setApplicationContext(context);
this.registry.setContentNegotiationManager(new ContentNegotiationManager());
}
@Bean
public ScriptTemplateConfigurer handlebarsConfigurer() {
ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
configurer.setEngineName("nashorn");
configurer.setScripts("/static/polyfill.js",
"/META-INF/resources/webjars/handlebars/3.0.0-1/handlebars.js",
"/static/render.js");
configurer.setRenderFunction("render");
configurer.setSharedEngine(false);
return configurer;
}