gpt4 book ai didi

eclipse - resources.groovy 中的 Grails bean 配置在 Eclipse STS 中失败

转载 作者:行者123 更新时间:2023-12-02 15:14:16 25 4
gpt4 key购买 nike

我们将 Eclipse STS 用于一个简单的 Grails 项目。我们从一些简单易懂的基础知识开始,这几乎是最基本的。该项目有一个简单的 Controller 和一个通过resources.groovy 连接的java bean。无论我们做什么,我们似乎都无法正确连接 bean,Grails 提示 bean 属性不可写或可能没有 getter/setter....

/* TestBean.groovy */
class TestBean {
def message
String getMessage(){
return message
}
}

.
/* resources.groovy */
import com.ofi.test.TestBean;

beans = {
helloWorldBean( TestBean){
message = "HelloWorld"
}
}

.
/* TestController */
class TestController {

def index = { }

def helloWorldBean
def show = {
def message = helloWorldBean.message
render message
}
}

.
/* UrlMappings.groovy */
class UrlMappings {
static mappings = {

"/test/$var"(controller:"Test"){
action = [GET: "get"]
}
}

.

项目编译,但是当应用程序在 Eclipse 中加载时我们收到以下错误消息(我们甚至无法访问 Controller ,TestBean 配置失败)
2011-08-10 11:18:55,252 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'helloWorldBean': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'message' of bean class [com.ofi.test.TestBean]: Bean property 'message' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldBean': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'message' of bean class [com.ofi.test.TestBean]: Bean property 'message' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)

最佳答案

由于您的 bean 是 groovy bean ,你甚至不需要访问器。以下应该没问题:

class TestBean {
def message
}

在您的情况下,错误的发生可能是因为 message字段输入为 def ,但您的访问器键入为 String .如果您必须在那里有访问器,请尝试输入相同的内容。

关于eclipse - resources.groovy 中的 Grails bean 配置在 Eclipse STS 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7013639/

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