Grails 从控制器渲染在开发中工作正常,但在测试中没有

Grails 从控制器渲染在开发中工作正常,但在测试中没有,grails,groovy,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 v

我的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()]
}
当我使用
grailsrun-app
运行我的应用程序时,上面的代码运行良好。但是,当我部署由
grails test war target/myapp.war创建的war文件时,上面的代码不起作用,并且出现“Page not found”错误,即使调试语句
在仍然打印时出现

我也尝试过在开发中使用
grails测试运行应用程序运行这个应用程序,但即使这样,上面的方法也不起作用。有趣的是,当我在
prod
模式(
grailsprod-run-app
)下运行应用程序时,一切都很好。因此,这肯定与
测试环境有关

另外,为了确保没有任何数据差异,我将dev test和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 = ""
        }
    }
}

如何解决此问题或进一步排除故障???

使用默认的“开发”数据源运行应用程序,不要将其与“测试”环境混淆。检查Config.groovy(edit:和DataSource.groovy)并确保在环境中配置了测试{}

更多信息可以在grails文档中找到:

我知道这一点。但这并不能回答我试图解决的问题。测试配置正确,应用程序在测试环境中运行良好(上述代码除外),您的开发和测试数据源是否以相同的方式设置?您在每个中为dbCreate传递什么值?为了确保我的开发和测试设置相同,我将它们指向相同的数据源(我的开发)。这不是数据问题,我建议尝试使用grails dev war target/sift.war生成一个war文件,看看是否存在同样的问题。如果这是一个环境问题,这将有助于缩小范围。显然,这只是为了测试。当我使用
grails prod run app
运行我的应用程序时,渲染也会按预期工作。在测试环境中,似乎缺少dbCreate属性。它应该是创建、删除或更新