gpt4 book ai didi

spring - Grails Rest Client Builder 抛出 OperationNotSupported

转载 作者:行者123 更新时间:2023-12-05 01:26:57 24 4
gpt4 key购买 nike

我正在尝试开发一个 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
}
}

我正在从 Controller 调用这个服务方法....

    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 实例化来设置代理设置,但它没有任何影响。

感觉我一定是遗漏了一些与插件配置相关的东西,但一直无法找到问题所在。任何建设性的意见将不胜感激。

-吉姆

最佳答案

no-arg constructor of RestBuilder通过 Collections.emptyMap() 创建一个不可变映射,稍后在某些情况下会尝试在该映射上执行 put()(例如,如果您通过系统定义了 HTTP 代理特性)。一种解决方法是使用显式、可变的 Map 构造您的 rest bean:

rest(grails.plugins.rest.client.RestBuilder, [:])

我还没有检查这个明显的错误是否已在 JIRA 中归档。如果没有,创建票证并附上您的示例应用程序可能是值得的。

关于spring - Grails Rest Client Builder 抛出 OperationNotSupported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22236421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com