Skip to content

View not loaded when Spring Boot static resource locations has a file system entry  #17303

Closed

Description

@mcollovati

Description of the bug

If the project set a filesystem location (e.g. file:web/static/) in the spring.web.resources.static-locations setting of application.properties file, the application fails to load views with a not-blank route path, when they are accessed directly by their URL (e.g. http://localhost:8080/mytest).

When accessing the page, depending on the static-locations configuration, the request ends in an error that may be a java.io.FileNotFoundException: /absolute/path/to/web/static/mytest for absolute paths or java.lang.IllegalArgumentException: URI is not hierarchical for relative paths.

The reason is that SpringVaadinServletService.getResourceURL() returns a valid URL also for non-existing resources.
In the above link example, the URL is file:web/static/mytest.
Classpath locations work, because when Resource.getUrl() is invoked they throw an IOException that is handled by SpringVaadinServletService

Expected behavior

StaticFileServer should ignore not-existing resources, allowing the view to be shown correctly

Minimal reproducible example

  • Create a new Vaadin project npx @vaadin/cli init my-app
  • Edit application.properties and add spring.web.resources.static-locations=file:web/static (it doesn't matter if the location exists or not)
  • Open the browser and navigate to http://localhost:8080/about
  • Verify that an error happens and the view is not shown

Versions

  • Vaadin / Flow version: 24.1, but probably all other versions are affected
  • Java version: 17
  • OS version: Linux
  • Browser version (if applicable):
  • Application Server (if applicable): Spring Boot with embedded Tomcat
  • IDE (if applicable):

Activity

  1. added 2 commits that reference this issue on Jul 28, 2023
    cf47342
    8959757
  2. added a commit that references this issue on Aug 2, 2023
    3d8c2b6
  3. added 6 commits that reference this issue on Aug 2, 2023
    562e1e6
    4cacd02
    5d0a54b
    075d0fc
    faff615
    7037a15
  4. vaadin-bot commented on Aug 8, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.2.0.alpha6 and is also targeting the upcoming stable 24.2.0 version.

  5. vaadin-bot commented on Aug 14, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 23.3.20.

  6. vaadin-bot commented on Aug 14, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.0.12.

  7. vaadin-bot commented on Aug 14, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.1.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions