我正在尝试开发一个Grails应用程序来调用一些REST服务......
我正在尝试使用Grails Rest Client Builder插件......
我已经尝试了几个版本的Grails ...目前在最新版本... 2.3.7虽然我也尝试了一些旧版本......
使用IntelliJ 13 ...启动了一个Grails项目......将一个快速的域类组合在一起...使用create-domain-class ...定义了一些字段和约束......然后生成了所有..
使用
在BuildConfig中定义Rest插件 compile ":rest-client-builder:2.0.0"
也试过2.0.1
我在spring / resources.groovy
中定义了rest bean// Place your Spring DSL code here
beans = {
rest(grails.plugins.rest.client.RestBuilder)
}
使用create-service生成一个服务......它非常简单
package myPackage
import grails.transaction.Transactional
@Transactional
class myService {
def rest
def serviceMethod() {
def resp = rest.get("http://myServer/myContextRoot/allEmployees")
return resp
}
}
我正在从控制器调用这个服务方法....
def search() {
myService.serviceMethod()
// Not really trying to do anything yet other than see
// if the bean gets injected properly and the method gets called.
render("Not yet implemented")
}
但是,当应用程序尝试启动时,我总是会收到Bean Instantiation Exception。
| Running Grails application
| Error 2014-03-06 16:11:02,310 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'rest': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
Message: Error creating bean with name 'rest': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by BeanInstantiationException: Could not instantiate bean class [grails.plugins.rest.client.RestBuilder]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by UnsupportedOperationException: null
->> 186 | put in java.util.AbstractMap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 69 | <init> in grails.plugins.rest.client.RestBuilder
| 57 | <init> . in ''
| 303 | innerRun in java.util.concurrent.FutureTask$Sync
| 138 | run . . in java.util.concurrent.FutureTask
| 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 918 | run . . in ''
^ 680 | run in java.lang.Thread
检查Grails源代码似乎对代理初始化所涉及的代码感到窒息,我试图摆弄bean实例化以设置代理设置,但它没有任何影响。
感觉我必须遗漏与插件配置相关的内容,但无法追踪问题。任何建设性的意见都是最受欢迎的。
-Jim
答案 0 :(得分:2)
no-arg constructor of RestBuilder
通过Collections.emptyMap()
创建一个不可变的映射,在某些情况下稍后会尝试put()
(例如,如果您通过系统属性定义了HTTP代理)。一种解决方法是使用显式的,可变的rest
:
Map
bean
rest(grails.plugins.rest.client.RestBuilder, [:])
我没有检查是否已在JIRA中提交了这个明显的错误。如果没有,那么创建一张票并附上你的示例应用程序可能是值得的。