好的,我现在看到问题不在于读取 xml 本身,而在于引导它,因为将服务名称更改为 lovercase 会有所帮助。我使用 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}
看起来 Bootstrap 没有“看到”可以在控制台上打印的变量。:/