'Serve static ressources in vaadin
I want some static resources to be served via HTTP by a vaadin14/spring-boot server.
As I understand from this blog post, there is a convention that all resources placed in META-INF/resources(and some other places) will be served as static content (web fragments)
As an example, i place the following file in:
src/main/resources/META-INF/resources/asd.txt
and maven puts it into JAR as expected:
META-INF/resources/asd.txt
When I ask for localhost:8080/asd.txt the results differ, depending on how the app was started:
- IDE/eclipse: works (Start the Application.main() method)
- packaged jar: the vaadin router picks up the request and thells me that there is no route available.
How do i tell vaadin/jetty (or whom ever?) to also serve this static repo when packaged?
We are using vaadin 14.7.0 with spring-boot-starter-parent 2.4.5
Solution 1:[1]
I had this issue but upgrading to Vaadin 23 and Spring boot 2.5.3 solved the issue for me.
Solution 2:[2]
It works also in a packaged jar, exactly as you describe. You can test by doing e.g.
npx @vaadin/cli init hello-resources
cd hello-resources
echo "Hello" > src/main/resources/META-INF/resources/asd.txt
mvn
Now http://localhost:8080/asd.txt returns "Hello"
mvn clean package -Pproduction
java -jar target/hello-resources-1.0-SNAPSHOT.jar
Now http://localhost:8080/asd.txt also returns "Hello"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Magnus |
| Solution 2 | Artur Signell |
