Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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
Grails 使用@I18nFields时方法编译错误的重复方法名称/签名_Grails_Internationalization_Grails 2.3 - Fatal编程技术网

Grails 使用@I18nFields时方法编译错误的重复方法名称/签名

Grails 使用@I18nFields时方法编译错误的重复方法名称/签名,grails,internationalization,grails-2.3,Grails,Internationalization,Grails 2.3,当我试图在我的域类中使用i18nFields来支持多种语言时,我得到了重复的方法名/签名编译失败 Grails版本:2.3.7(我尝试了2.3.4,但得到了相同的问题并进行了升级) Grails为此提供的文档是 我的域类看起来像 package com.sampleapp.domain import i18nfields.I18nFields; @I18nFields class Products { def name static constraints = {} static

当我试图在我的域类中使用
i18nFields
来支持多种语言时,我得到了重复的方法名/签名编译失败

Grails版本:2.3.7(我尝试了2.3.4,但得到了相同的问题并进行了升级)

Grails为此提供的文档是

我的域类看起来像

package com.sampleapp.domain

import i18nfields.I18nFields;

@I18nFields
class Products {

 def name

 static constraints = {}

 static i18nFields = ['name']
}
My
Config.groovy
包含以下行以指定区域设置

// internationalization support - testing 
i18nFields {
    locales = ['en','es']
}
BuildConfig.groovy插件定义

plugins {
    // plugins for the build system only
    build ":tomcat:7.0.47"

    // plugins for the compile step
    compile ":scaffolding:2.0.1"
    compile ':cache:1.1.1'

    // plugins needed at runtime but not for compilation
    runtime  ":hibernate:3.6.10.6" // or":hibernate4:4.1.11"//
    runtime ":database-migration:1.3.8"
    runtime ":jquery:1.10.2.2"
//  compile  ":jquery-ui:1.10.2.2"
    runtime ":resources:1.2.1"
    // Uncomment these (or add new ones) to enable additional resources capabilities
    runtime ":zipped-resources:1.0.1"
    runtime ":cached-resources:1.1"
    //runtime ":yui-minify-resources:0.1.5"

    compile ':platform-core:1.0.RC6'
    compile ":cache-headers:1.1.5"
    runtime ':spring-security-core:2.0-RC2'
    // internationalization
    compile ":i18n-fields:0.8.1"
}
编译错误为

grails-workspace\Test\grails-app\domain\com\sampleapp\domain\Products.groovy: -1: Repetitive method name/signature for method 'void setName_es(java.lang.String)' in class 'com.sampleapp.domain.Products'.
 @ line -1, column -1.
对于en和es区域设置的name属性,该错误会重复两次

如果我删除i18nFields注释,并且在此之前示例应用程序运行良好,则不会出现错误。我在控制器中验证了post的类似错误。我还进行了验证,以确保groovy版本是正确的,在我的例子中是2.1


有谁能给我一些建议,告诉我应该在哪里解决这个问题

这可能与Grails2.3中的新绑定机制有关。也许现在getter和setter是自动设置的

当我在ClassI18nalizator.groovy中注释掉这两行时,错误消失了。这似乎至少在一定程度上起了作用。我可以使用脚手架上的田地。这不是一个真正的解决方案,但可能是对比我更了解grails的人的一个提示

    private def getSetterMethod(field) {
            // setter should return void. that's why the return statement.
            //return new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.setValue(this, '${field}', value); return;").pop();
    }

    private def getGetterMethod(field) {
            //new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.getValueOrDefault(this, '${field[0..-7]}', '${field[-5..-1]}')").pop();
    }
之后,我遇到了第二个问题:

方法groovy.util.ConfigObject.contain()的签名无效 适用于参数类型:(java.lang.String)值:[en_US]

我通过向Config.groovy添加redisLocale解决了这个问题

i18nFields { 
    locales = ['de_DE', 'en_US']
    defaultLocale = "en_US"
    redisLocales = ['de_DE', 'en_US']
}

这可能与Grails2.3中的新绑定机制有关。也许现在getter和setter是自动设置的

当我在ClassI18nalizator.groovy中注释掉这两行时,错误消失了。这似乎至少在一定程度上起了作用。我可以使用脚手架上的田地。这不是一个真正的解决方案,但可能是对比我更了解grails的人的一个提示

    private def getSetterMethod(field) {
            // setter should return void. that's why the return statement.
            //return new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.setValue(this, '${field}', value); return;").pop();
    }

    private def getGetterMethod(field) {
            //new AstBuilder().buildFromString("i18nfields.I18nFieldsHelper.getValueOrDefault(this, '${field[0..-7]}', '${field[-5..-1]}')").pop();
    }
之后,我遇到了第二个问题:

方法groovy.util.ConfigObject.contain()的签名无效 适用于参数类型:(java.lang.String)值:[en_US]

我通过向Config.groovy添加redisLocale解决了这个问题

i18nFields { 
    locales = ['de_DE', 'en_US']
    defaultLocale = "en_US"
    redisLocales = ['de_DE', 'en_US']
}
感谢您的尝试(以及通过github;)让我了解)

这个问题是已知的,但尚未解决。 前面的答案(注释掉方法)并不准确,尽管它遵循了正确的方向,因为问题来自Grails中的新更改,这将导致getter和setter发生冲突

我找到的解决方案是分别创建属性和getter/setter,这似乎是可行的

我会尽快发布一个新版本,只要它能够在项目中进行全面测试,但如果您想使用它,代码已经在(版本0.9-redis-SNAPSHOT)中提供了。

感谢您的尝试(以及通过github让我知道的内容;)

这个问题是已知的,但尚未解决。 前面的答案(注释掉方法)并不准确,尽管它遵循了正确的方向,因为问题来自Grails中的新更改,这将导致getter和setter发生冲突

我找到的解决方案是分别创建属性和getter/setter,这似乎是可行的


一旦可以在项目中进行全面测试,我就会发布一个新版本,但是如果您想使用它,代码(版本0.9-redis-SNAPSHOT)中已经有了。

当您尝试将Java>v7与Grails<2.3.7的任何版本一起使用时,就会出现这个问题。降级jvm或升级grails。

当您尝试将Java>v7与grails<2.3.7的任何版本一起使用时,就会出现此问题。要么降级jvm,要么升级grails。

谢谢。你的解决方案奏效了。对于第二个问题wrt No signature method:groovy.util.ConfigObject.contain(),我在加载gsp时得到了相同的结果。我传递了language参数和字段名来解决这个问题。我还必须在Config.groovy中设置defaultLocale:i18nFields{locales=['de_de','en_US']defaultLocale=“en_US”}谢谢。你的解决方案奏效了。对于第二个问题wrt No signature method:groovy.util.ConfigObject.contain(),我在加载gsp时得到了相同的结果。我传递了language参数和字段名来解决相同的问题。我还必须在Config.groovy中设置defaultLocale:i18nFields{locales=['de_de','en_US']defaultLocale=“en_US”}我在grails 2.3.4中遇到了与jdk 1.8相同的问题,通过还原为我解决了这个问题。我在grails 2.3.4中遇到了与jdk 1.8相同的问题,还原为我解决了这个问题。试图在Java8SDK上运行Grails2.3.5时,到处都会出现此错误。我安装了我能找到的最新版本的Java7SDK,它工作起来很有魅力。谢谢,这个。试图在Java8SDK上运行Grails2.3.5时,到处都会出现此错误。我安装了我能找到的最新版本的Java7SDK,它工作起来很有魅力。非常感谢。