在 Grails 2.x 中,可以执行以下操作:
class UrlMappings {
static mappings = {
/**
* Serving the index.html directly
*/
"/"(uri: "/ng/app/index.html")
}
}
假设 web-app/ng/app/
目录中有一个 index.html
文件。现在,当我们在 Grails 2 中浏览 URL http://localhost:8080
时,index.html
会自动呈现。
在 Grails 3 中,我在 src/main/webapp/
中添加了相同的 index.html
文件,我可以像 http:///localhost:8080/static/index.html
.
因此,我尝试在 UrlMappings.groovy
中执行相同操作:
class UrlMappings {
static mappings = {
/**
* Serving the index.html directly
*/
"/"(uri: "/static/index.html")
}
}
但这给了我错误{"message":"Internal server error","error":500}
:
ERROR org.grails.web.errors.GrailsExceptionResolver - UrlMappingException occurred when processing request: [GET] /
Unable to establish controller name to dispatch for [null]. Dynamic closure invocation returned null. Check your mapping file is correct, when assigning the controller name as a request parameter it cannot be an optional token!. Stacktrace follows:
grails.web.mapping.exceptions.UrlMappingException: Unable to establish controller name to dispatch for [null]. Dynamic closure invocation returned null. Check your mapping file is correct, when assigning the controller name as a request parameter it cannot be an optional token!
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我使用 Grails 3.1.8 Angular 配置文件创建了我的应用程序,后来删除了与 Angular 相关的内容,例如 Grails GSP 插件、 Assets 管道等。
最佳答案
这似乎是 Grails 3 的一个未决问题,预计将在 Grails 3.2.0 中得到解决。
关于grails - 在 Grails 3 中将静态文件呈现为 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139553/