Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java StreamingTemplateEngine在编译groovy代码后停止工作_Java_Groovy - Fatal编程技术网

Java StreamingTemplateEngine在编译groovy代码后停止工作

Java StreamingTemplateEngine在编译groovy代码后停止工作,java,groovy,Java,Groovy,我将获得以下代码,以使用模板创建设置文件: def config_template = this.class.getResource('/config.txt.template') def template = new groovy.text.StreamingTemplateEngine(config_template) def template_data = [ data1: [ datadict1: this.class.getResource('file1.xml'),

我将获得以下代码,以使用模板创建设置文件:

def config_template = this.class.getResource('/config.txt.template')
def template = new groovy.text.StreamingTemplateEngine(config_template)
def template_data = [
  data1: [
    datadict1: this.class.getResource('file1.xml'),
    datadict2: this.class.getResource('file2.xml'),
    cert: this.class.getResource('cert1.jks'),
  ],
  data2: [
    datadict1: this.class.getResource('file3.xml'),
    datadict2: this.class.getResource('file4.xml'),
    cert: this.class.getResource('cert2.jks'),
  ]
String sessions_config_text = template.make(template_data)
File sessions_config = new File().with { f ->
  f.withWriter('UTF-8') { w ->
    w.write(sessions_config_text)
  }
  return f
}
该代码被编译并打包到jar文件中。当我运行它时,我得到:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
    at java.lang.Thread.run(Thread.java:745)
Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.text.StreamingTemplateEngine.make() is applicable for argument types: (java.util.LinkedHashMap) values: [[data1:[datadict1:null, datadict2:null, cert:null, ...]]
Possible solutions: wait(), any(), wait(long), use([Ljava.lang.Object;), each(groovy.lang.Closure), any(groovy.lang.Closure)
这让我想到
StreamingTemplateEngine.make()
将只接受groovy的
Map
类型,但是当代码编译成java时,
Map
将变成
LinkedHashMap
并且
make()
方法签名将无效


是这样吗

如果是这样,如何使模板引擎工作


如果没有,我做错了什么?如何修复它?

首先,您需要创建with方法的实例。然后您可以调用创建的模板。

我意识到问题所在,这只是一个简单的错误销售。谢谢你的回答。@sargas那么你的打字错误与答案有关吗?这个问题的未来访问者可能会被问到实际解决方案中。@cfrick否。我调用了
create\u template
方法,而不是
createTemplate
。所以,我认为对来访的人没有好处。