我正在尝试为我的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. 为什么生成第一个类?我的代码中没有任何其他类。只有捕获脚本和扩展的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)我也发过同样的问题这里
发布于 2013-08-30 17:07:42
我无法深入解决这种奇怪的行为,但有一个更简单的解决办法。我将其添加到将所有请求定向到单个脚本中。
<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>发布于 2015-08-24 15:49:23
必须更正我以前的回答:修复不是我之前发布的代码更改,而是将评级从2.4.3降到2.3.9。在2.4.3中,GroovyServlet本身工作正常,但是扩展它的setVariables、getScriptUri、getResourceConnection和getScriptUriAsFile确实导致了命名问题。
还在进一步调查。
https://stackoverflow.com/questions/18472683
复制相似问题