grails - 在 Grails 3 中将静态文件呈现为 URI

标签 grails grails-3.1

在 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 中得到解决。

https://github.com/grails/grails-core/issues/9908

关于grails - 在 Grails 3 中将静态文件呈现为 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38139553/

相关文章:

grails - 移植到grails 3时将MappingFactory转换为ToMany的ClassCastException

templates - Grails g:include标签包含 Controller 调用

javascript - 我想在渲染模板后使用onclick事件

rest - Grails 3 应用程序中 POST 中的 header 不会随其余服务一起发送

grails - 适用于 Grails 3.x 的 Gradle DSL

maven - 增加 gradle 的超时时间以获得 Maven 依赖

grails - 耐火 Material 处理不当

grails - Grails获取A的列表,其中以多对多关系与B进行搜索

mongodb - 使用 GORM MongoDB 插件实现接口(interface)的持久类

grails - grails3.x 中就地插件代码的更改不会自动重新加载