好的,我現在看到問題不在於閱讀xml本身,而是隨着它的引導,因爲更改服務名稱以幫助情侶。我使用ReaderService來讀取帶有地址的xml文件並構建地址對象。這裏是我的引導代碼: `
class BootStrap {
def readService
def init = {
servletContext ->
def xml = readService.read()
println xml
def adress = new mobilmed.Adres(ulica:xml.adress.street, dom:xml.adress.house, miejscowość:xml.adress.residance, kodPocztowy:xml.adress.postCode, poczta:xml.adress.post).save()
if(adres.hasErrors()){
println adres.errors}
}
}
當我運行它,我得到了經典的「沒有這樣的財產」的錯誤。
| Error 2012-08-28 06:42:36,784 [pool-7-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: No such property: adres for class: BootStrap
Message: No such property: adres for class: BootStrap
Line | Method
->> 10 | doCall in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 301 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 294 | executeForEnvironment . . . . . in ''
| 270 | executeForCurrentEnvironment in ''
| 303 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 662 | run . . . . . . . . . . . . . . in java.lang.Thread
當然,我檢查,併爲Boostraping定義的變量工作得很好,像這樣:
def karolzam = new mobilmed.Adres(ulica:"Turkusowa", dom:"8/22", miejscowość:"Lublin", kodPocztowy:"20-572", poczta:"Lublin").save()
if(karolzam.hasErrors()){
println karolzam.errors}
貌似引導不「看」的變量,可以在控制檯上打印。 :/