使用app.context时,Grails重定向到错误的地址?

Pol*_*878 5 java model-view-controller grails groovy

redirect当我app.context以某种方式设置时,我注意到一些奇怪的行为.我在Grails JIRA中发现了一个错误,它完美地描述了我的问题,但它被标记为UTR:http://jira.grails.org/browse/GRAILS-7546


以下是我对问题的描述:
我目前正在使用Grails 2.0M2.我在application.properties文件中定义了以下属性:

app.context=/
app.name=foobar
Run Code Online (Sandbox Code Playgroud)

当我redirect在控制器中调用时,redirect将应用程序名称添加到我提供的uri上,然后生成404.以下是我这样做的方式:

String partialUrl = createLink(mapping: 'helloworld') // returns `/hello/world`
redirect(uri: partialUrl) // INCORRECTLY redirects to 
                          // `http://mysite.com/foobar/hello/world`
                          // instead of `http://mysite.com/hello/world`
Run Code Online (Sandbox Code Playgroud)

假设我有一个名为helloworld在我的UrlMappings.groovy文件中定义的URL映射,其路径为/hello/world.

所以,长话短说,如果我设置app.context为/,我不希望它app.name出现在我的最终重定向URL中.

这是一个错误还是预期的行为?有什么想法,我可以建立重定向网址,而无需做太多的手动步骤?

小智 0

这不是对你的问题的直接回答,但我的做法是:我从不修改 grails 属性中的 app.context ,因为 tomcat 在生产中覆盖它,并且我不关心它在我的开发中使用哪个上下文。