Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Serving springboot-app static resources from AppEngine

Hello

I hace a spring-boot application deployed with AppEngine. Static resources are located inside .jar (classes/static/...)

I tried to configure app.yaml with this documentation: https://cloud.google.com/appengine/docs/standard/java11/serving-static-files but I get this error: logMessage"Static file referenced by handler not found: /static/images ...

My app.yaml looks like: 

entrypoint: "java -noverify -jar myjar.jar -cp BOOT-INF/classes/:BOOT-INF/lib/* com.....config.Application"
instance_class: "@appengine.instance.class@"
inbound_services:
- warmup
vpc_access_connector:
name: "projects/@cloud.application@/locations/@cloud.region@/connectors/@cloud.redis.connector@"
handlers:
- url: /resources/(.*)$
static_files: /static/\1
upload: /static/.*\.(png)$
require_matching_file: false

I changed static_files adding BOOT-INF, BOOT-INF/classes ...

Solved Solved
0 5 2,177
1 ACCEPTED SOLUTION

@smk-davidrodrig 

This is working for me: (app.yaml)

...
entrypoint: java -noverify -cp "BOOT-INF/resources/:BOOT-INF/classes/:BOOT-INF/lib/*" com.myorg.MySpringBootApp

handlers:
  - url: /(.*\.(gif|png|jpg|svg|ico|css|js|html))$
    static_files: BOOT-INF/classes/static/\1
    upload: BOOT-INF/classes/static/.*\.(gif|png|jpg|svg|ico|css|js|html)$
    secure: always

  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

...


1. unzip server.jar
2. rm server.jar. This leaves the following folders/files for deployment:

BOOT-INF
META-INF
app.yaml
org

3. gcloud app deploy... 

Now you'll see that e.g. your js-Files have appropriate headers:

...
cache-control: public, max-age=600
content-encoding: gzip
etag: "uh4VxA"
...



View solution in original post

5 REPLIES 5

Based on the error message, it appears that the folder static/images doesn’t exist, or the file is missing. To fix, review the handlers section of app.yaml and make sure that the referenced files exist within the application folder.

Furthermore, from the looks of it, it doesn't appear that the handler section in your app.yaml file conforms to the recommended configuration in GCP's guide (see step 3). So in addition to ensuring that the file exists, ensure to follow the guide as closely as possible. 

If after doing the above, the error persists, I suggest opening a support case that way GCP support can troubleshoot the issue and recommend a solution tailored to your use case. Consider posting on other sites such as Stack Exchange, Stack Overflow, etc as well because you may obtain more comprehensive answers from other users who have experienced the same error.

 

@smk-davidrodrig Have you been able to resolve your issue to serve static files from a Spring Boot JAR?

I am also following this guide: https://cloud.google.com/appengine/docs/standard/java11/serving-static-files

 

But with no success 😞

Hello @michaelhunziker !

We are working on it but not luck. Same issue.

Thx

@smk-davidrodrig 

This is working for me: (app.yaml)

...
entrypoint: java -noverify -cp "BOOT-INF/resources/:BOOT-INF/classes/:BOOT-INF/lib/*" com.myorg.MySpringBootApp

handlers:
  - url: /(.*\.(gif|png|jpg|svg|ico|css|js|html))$
    static_files: BOOT-INF/classes/static/\1
    upload: BOOT-INF/classes/static/.*\.(gif|png|jpg|svg|ico|css|js|html)$
    secure: always

  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

...


1. unzip server.jar
2. rm server.jar. This leaves the following folders/files for deployment:

BOOT-INF
META-INF
app.yaml
org

3. gcloud app deploy... 

Now you'll see that e.g. your js-Files have appropriate headers:

...
cache-control: public, max-age=600
content-encoding: gzip
etag: "uh4VxA"
...



Yes! Similar to us ... using jenkins:

First setp:

...
clean package
appengine:stage 
...

Next unzip ... and:

...
appengine:deploy
...

 Seems that it is the same ... 

On the other hand we are working on serve the static files from google cloud storage but we have to change app source code.

Many thanks for your support