我們使用Eclipse STS作爲簡單的Grails項目。我們從一些簡單的東西開始理解基礎知識,並且這是基本的。該項目有一個簡單的控制器和一個通過resources.groovy連接的java bean。無論我們做什麼,我們似乎無法得到正確的有線豆,Grails的抱怨bean屬性是不可寫或可能不會有一個getter/setter方法....resources.groovy中的Grails bean配置在Eclipse中失敗STS
/* 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(我們甚至不能得到控制,中,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)
我的印象是,他們不是在Grails的要求下? – raffian
它可能是1)只有定義了setter和2)字段沒有更強類型的組合。 –
訪問器不是必需的,添加它們不應該有任何區別 –