finatra使用mustache模板,本地文件配置

了便于调试方便,本地的*.mustache模板,需要从硬盘读取,不需要做cache缓存.类似nginx的lua也有cache开关

1) 设置ide的运行参数

-http.port=:5000 -local.doc.root=F:\template

调试模式使用 local.doc.root标志将会触发本地文件模式.(Finatra版本> v1.x) 

不能同时使用 local.doc.root + doc.root 

官方文档的描述如下:

To serve files from the local filesystem, set the flag -local.doc.root to the location of the file serving directory. Note that setting Java System Property -Denv=env is no longer required nor supported. Setting the -local.doc.root flag will trigger the same localFileMode behavior from Finatra v1.x.

Also note that it is an error to attempt to set both the -doc.root and the -local.doc.root flags. Either

  • do nothing to load resources from the classpath root or

  • configure a classpath “namespace” by setting the -doc.root or

  • load files from a local filesystem directory location specified by the -local.doc.root flag.

Additionally, it is recommend to use local filesystem serving only during testing and not in production. It is recommended that you include files to be served as classpath resources in production.

如果是生产环境,则需要使用-doc.root来配置classpath

关于template模板文件,具体在哪个目录下面,可以通过变量设置

默认是在resources目录下面,当然也可以修改

-mustache.templates.dir=newtemplate

-mustache.templates.dir=com\web_test\templatesxxabc

这样可以将模板文件通过cache缓存起来.

resources\newtemplate\abc.mustache

注意:

同时设置2个参数,会冲突,将会提示:

4) Error injecting constructor, java.lang.AssertionError: assertion failed: Cannot set both -local.doc.root and -doc.root flags.

  at com.twitter.finatra.http.routing.FileResolver.<init>(FileResolver.scala:28)

  at com.twitter.finatra.http.routing.FileResolver.class(FileResolver.scala:27)


你可能感兴趣的:(finatra使用mustache模板,本地文件配置)