首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ConversionNotSupportedException:未能将“grails.spring.BeanBuilder”类型的属性值转换为所需的“java.lang.String”类型

ConversionNotSupportedException:未能将“grails.spring.BeanBuilder”类型的属性值转换为所需的“java.lang.String”类型
EN

Stack Overflow用户
提问于 2014-01-27 18:10:08
回答 2查看 3.7K关注 0票数 0

我正在开发这个grails-aws插件,在Grails2.3.4和2.3.5下运行时会出现一个奇怪的错误。

参见travis构建输出,Grails2.0.4/ 2.2.4测试通过,2.3.4 / 2.3.5测试失败

在从配置文件读取值的区域中,grails2.3.x是否发生了一些变化?

创建名为“credentialsHolder”的bean时出错:初始化bean失败;嵌套异常为org.springframework.beans.ConversionNotSupportedException:未能将属性' grails.spring.BeanBuilder‘的属性值转换为属性’accessKey‘的必需类型' java.lang.String’;嵌套异常为java.lang.IllegalStateException:无法将grails.spring.BeanBuilder类型的值转换为属性“accessKey”的必需类型java.lang.String:未找到匹配的编辑器或转换策略(注意:已筛选堆栈跟踪)。使用--详细地查看整个跟踪。)

代码语言:javascript
复制
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'credentialsHolder': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.spring.BeanBuilder' to required type 'java.lang.String' for property 'accessKey'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [grails.spring.BeanBuilder] to required type [java.lang.String] for property 'accessKey': no matching editors or conversion strategy found
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-30 17:23:07

这在这个Grails JIRA中得到了解释--显然,BeanBuilder使用“委托优先”的行为调用它的闭包,但是以前在Groovy中有一个bug,它意味着与包含作用域的static方法匹配的调用忽略了解决策略设置,并且无论如何都调用了静态方法。换句话说,您以前使用过的代码只是偶然使用过的。如果将静态方法限定为类名AwsPluginSupport.read(...),则仍然可以调用它。

或者,您可以跳过整个过程--为bean属性使用文字'${....}'表达式,并让属性占位符机制为您从配置中提取值。即代替

代码语言:javascript
复制
credentialsHolder(AWSCredentialsHolder) {
        accessKey  = readString("credentials.accessKey")
        secretKey  = readString("credentials.secretKey")
        properties = readString("credentials.properties")
}

使用

代码语言:javascript
复制
credentialsHolder(AWSCredentialsHolder) {
        accessKey  = '${grails.plugin.aws.credentials.accessKey}'
        secretKey  = '${grails.plugin.aws.credentials.secretKey}'
        properties = '${grails.plugin.aws.credentials.properties}'
}

请注意,这些字符串是单引号字符串(因此值是一个表达式,包括${},Spring可以解析),而不是双引号的GStrings (解析时不能由Groovy解析)。

票数 1
EN

Stack Overflow用户

发布于 2014-01-31 03:37:14

拉请求作为解决此问题的方法提交。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21388387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档