java - 将应用部署到 Google Cloud 平台时未检测到相对文件路径
问题描述
在本地一切正常,但是一旦我将我的应用程序部署到 App Engine。谷歌云没有获取相对文件路径
解决方案
根据Where to put your static files ,
您必须将静态提供的文件放在应用程序的 webapp 目录中。您可以使用文件夹,但请记住所有文件路径和 URI 都是相对于 webapp 目录的。
为静态文件选择位置后,您必须使用元素在 appengine-web.xml 文件中定义它们的位置。
一个如何配置的例子是:
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
<static-files>
<include path="/**.html" >
</include>
</static-files>
</appengine-web-app>
此外,在文档中:[直接从您的应用提供文件](https://cloud.google.com/appengine/docs/standard/java11/serving-static-files#serving_from_your_application),它提到:
要在标准环境中为 Java 11 提供静态文件,您可以使用 static_dir 或 static_files 元素在 app.yaml 文件中定义处理程序。
例如,以下行指示浏览器加载 main.css
文件:
<link type="text/css" rel="stylesheet" href="/static/css/main.css">
该./public
目录在static_dir
项目文件的元素中定义app.yaml
:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
- url: /static
static_dir: public
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
推荐阅读
- jdbc - 在 Micronaut 中,如何使用纯 jdbc 行映射?(踢出 ORM-Hibernate)
- oracle - 如何以编程方式模拟 Oracle 服务器关闭
- angular - 如何使用模拟服务对 Angular 中的(非组件)支持类进行单元测试
- javascript - html如何识别一段javascript代码中的html标签?
- python - 即使安装了 Pandas 模块,也找不到它
- postgresql - 如何在 GORM 中做 bytea?
- java - 如何在messageFormat中添加字符串
- node.js - 如何根据用户提供的过滤器执行多层临时聚合?
- java - List 中的 return 语句
方法? - identityserver4 - 如何将上下文从 MVC 传递到 IdentityServer 登录操作