我无法访问 Grails 3 中的 web-app 文件夹文件。我robots.txt
在 web-app 文件夹中有,而在 Grails 2 中,我可以直接在http://localhost:8080/robots.txt
. 迁移到 Grails 3 后,我无法在http://localhost:8080/robots.txt
.
如何使这些文件再次可访问?
我无法访问 Grails 3 中的 web-app 文件夹文件。我robots.txt
在 web-app 文件夹中有,而在 Grails 2 中,我可以直接在http://localhost:8080/robots.txt
. 迁移到 Grails 3 后,我无法在http://localhost:8080/robots.txt
.
如何使这些文件再次可访问?
请参阅https://github.com/grails/grails-core/releases/tag/v3.0.12和部分Location of static resources
在 Grails 3 中,您可以将文件存储在 src/main/resources 下。您可以通过static
以 example开头的文件名访问它们http://localhost:8080/static/robots.txt
。
可以使用附加 URL 中定义的配置选项更改此路径
我在 Grails 3.3.1 中遇到了类似的问题。我必须访问文件模板才能将其与插件(excel-export 插件)一起使用。阅读文档后,我将文件放在 src/main/resources 下。它在开发模式下正常工作(grails run-app),但我在生产环境中收到错误(grails war)。经过大量阅读,我找到了使其工作的方法。我让文件在同一个目录(src/main/resources)中,然后在我的控制器中:
def template = this.class.classLoader.getResource('myExcelFile.xlsx')
def path = template.file //will give you the real path to your file
有了路径,您就可以打开一个流或做您需要做的事情。就我而言,将它与插件一起使用:
new WebXlsxExporter(path).with {
setResponseHeaders(response)
add(products, withProperties)
save(response.outputStream)
}