将我的应用程序部署到Google Cloud平台时未检测到相对文件路径

问题描述 投票:0回答:1

在本地,一切正常,但是,一旦我将我的应用程序部署到App Engine。相对文件路径没有被Google Cloud拾取

java spring-boot google-cloud-platform filepath
1个回答
0
投票

根据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
© www.soinside.com 2019 - 2024. All rights reserved.