Groovy Groovlet出现重复类错误

Groovy Groovlet出现重复类错误,groovy,groovlet,Groovy,Groovlet,我正在尝试为我的Groovlet使用一个全面的groovy脚本。这就是我所做的 public class GroovletServletCatchAll extends GroovyServlet { public URLConnection getResourceConnection(String name) throws ResourceException { return super.getResourceConnection("CatchAll.groovy"

我正在尝试为我的Groovlet使用一个全面的groovy脚本。这就是我所做的

public class GroovletServletCatchAll extends GroovyServlet { 
    public URLConnection getResourceConnection(String name) throws ResourceException { 
        return super.getResourceConnection("CatchAll.groovy"); 
    } 
}
现在,对于
CatchAll.groovy
文件中的任何代码,我得到了错误

jndi:/localhost/web_app/CatchAll.groovy: 1: 
Invalid duplicate class definition of class CatchAll. 
One of the classes is an explicit generated class using the class statement, 
the other is a class generated from the script body based on the file name. 
为什么要生成第一个类?我的代码中没有任何其他类。只有Catch all脚本和扩展servlet


这是我得到上述错误的剥离代码

  println """
  Hello, ${request.remoteHost}: ${new Date()}
  """
奇怪的是,如果我删除上面的
new Date()
子句,第一个错误就会消失,我会在CatchAll构造函数中得到一个stackOverflow(继续调用自身)

这就是我在日志中看到的重复(以及其他跟踪)

    at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
    at groovy.lang.Script.<init>(Script.java:40)
    at groovy.lang.Script.<init>(Script.java:37)
    at CatchAll.<init>(CatchAll.groovy)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
位于groovy.lang.GroovyObjectSupport。(GroovyObjectSupport.java:32)
位于groovy.lang.Script。(Script.java:40)
位于groovy.lang.Script。(Script.java:37)
在CatchAll。(CatchAll.groovy)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)

我也发布了同样的问题

我无法深入到足够的深度来解决这个奇怪的行为,但有一个更简单的解决方案。我添加此命令是为了将所有请求定向到单个脚本

<init-param>
    <param-name>resource.name.replacement</param-name>
    <param-value>CatchAll.groovy</param-value>
</init-param>

<init-param>
    <param-name>resource.name.regex</param-name>
    <param-value>/.*</param-value>
</init-param>

resource.name.replacement
CatchAll.groovy
resource.name.regex
/.*

必须纠正我之前的回答:修复不是我之前发布的代码更改,而是从2.4.3降级到2.3.9。在2.4.3中,GroovyServlet本身工作正常,但扩展其setVariables、getScriptUri、getResourceConnection和getScriptUriAsFile确实会导致命名问题


仍在进一步调查。

CatchAll.groovy是什么样子的?我尝试了最简单的脚本(一行程序),但一直失败。你能发布你尝试的脚本的代码吗?@tim_yates:请查看主要内容中的更新。