grails 2.5+在控制器上实现serializable时出现重复的类定义错误

时间:2017-03-26 17:46:18

标签: grails

升级传统的grails系统。其中一个控制器实现了Serializable。这会在较新版本的grails中引发以下错误:

Invalid duplicate class definition of class com.regional.ScheduleController : 
The source contains at least two definitions of the class. 
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. 
Solutions are to change the file name or to change the class name.

提到的解决方案将破坏(之前的)grails惯例。任何人都知道如何处理grails 2.5 +?

修改

Serializable不是问题。我尝试删除它并得到了同样的错误。 我从another question找到了这个解释:

IN groovy.. class B{} is a class structure and defines a class B. 
Scripts are classes too.
 Now you may create a B.groovy, with the content "class B{}; def b = new B()". 
There would be one class named B, and a script with the very same name.
This is a conflict.  

然而,这并不能解释为什么它在grails 2.5以下运行良好而不是在它之上。我无法找到像上面提到的那个控制器中的def冲突。

ANSWER : 其中一个导入实际上是失败的 - 导致groovy根据当前文件名生成类定义。当它达到类定义时,已经有一个自动生成的类名要碰撞。

0 个答案:

没有答案