从控制器渲染在开发中工作正常但不在测试中

时间:2013-09-20 16:33:23

标签: grails groovy

我的grails应用程序中有以下代码:

def list () {
  def roles = principal.authorities*.authority
  def page = roles.contains("ROLE_ADMIN")? "allcolors": "usercolors"
  if (params.sort == "latest" || params.sort == null) {
    logger.debug("came in if");
    render view: page, model: [colorlist: colorService.colorList()]
  } 
  else
    render view: page, model: [colorlist: colorService.colorListForUser()]
}

当我使用grails run-app运行我的应用程序时,上面的代码运行正常。但是,当我部署由grails test war target/myapp.war创建的war文件时,即使调试语句came in if仍然被打印,上述代码也无法正常工作并且出现“找不到页面”的错误。

我已尝试使用grails test run-app在开发中运行此应用,但即便如此,上述操作也无效。有趣的是,当我以prod模式(grails prod run-app)运行应用程序时,一切正常。所以它肯定与test环境

有关

另外,为确保没有任何数据差异,我已将dev测试和prod更改为指向同一开发数据库。

可能是我的应用程序对测试环境有一些特殊设置,我没有看到......这会导致“渲染”不起作用?

我的环境如下:

    environments {
        development {
            grails.logging.jul.usebridge = true
        }
        test {
            grails.logging.jul.usebridge = true
        }
        production {
            grails.logging.jul.usebridge = false
        }
    }

And DB config looks like this:

environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/myapp?useUnicode=yes&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"
            username = "root"
            password = ""
        }
        hibernate {
        }
    }
    test {
        dataSource {
            dbCreate = 
            url = "jdbc:mysql://localhost/myapp?useUnicode=yes&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"
            username = "root"
            password = ""
            properties {
            }
            hibernate {
            }
        }
    }
    production {
        dataSource {
            dbCreate = "create-drop"
            url = "jdbc:mysql://localhost/myapp?useUnicode=yes&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"
            username = "root"
            password = ""
        }
    }
}

我如何解决这个问题或进一步排除故障?

1 个答案:

答案 0 :(得分:0)

run-app使用默认的“开发”数据源运行,不要与“测试”环境混淆。检查您的Config.groovy(编辑:和DataSource.groovy)并确保在您的环境中配置了测试{}。

更多信息可以在这里的grails文档中找到: http://www.grails.org/Environments