vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
609 stars 167 forks source link

Vaadin 10 can't load resources in Spring Boot App #4348

Closed ilya-ershov closed 6 years ago

ilya-ershov commented 6 years ago

I beleive I have found 2 ways to reproduce the same issue. At least they seem similar. The first one described here: https://vaadin.com/forum/thread/16988003/17150030 If package vaadin app as fat jar - browser can't load styles/resources (404 error). If package as War - it works as expected. Its great disappointment, but not a blocker for now.

The next one is great blocker. This one is easy reproducible:

  1. I use Oracle java version "10.0.1" 2018-04-17 on Windows 10 machine
  2. git clone https://github.com/spring-guides/gs-crud-with-vaadin.git
  3. Go into 'complete' project and edit build.gradle to:
  4. Add jaxb dependency: compile "javax.xml.bind:jaxb-api:2.3.0"
  5. Add plugins { id "com.github.ManifestClasspath" version "0.1.0-RELEASE" } because on windows it fails with too long classpath error
  6. Add springBoot { mainClassName = 'hello.Application' }
  7. Execute gradle bootRun
  8. Open in browser localhost:8080

Expected: styles and other resources are loaded successfully (2xx codes) Actual: 404 image

Issue is reproducible for Windows. But if use Windows Linux Subsystem - it works as expected. I'm pretty sure that addition manifest classpath plugin breaks expected behaviour on Windows, because on other projects its addition also breaks. Its not the only plugin I tried. id "ua.eshepelyuk.ManifestClasspath" version "1.0.0" does the same, so I assume that is not specific for plugin, but rather is vaadin 10 issue.

Attached sample project: complete.zip

Legioth commented 6 years ago

EDIT: I just realized that the ticket is actually about the second issue described in the introduction. I'll leave my original reply here since it's still related.

This is not in any way specific to Vaadin 10, but rather a generic difference between WAR and JAR packaging. On the other hand, previous Vaadin versions used a non-standard convention and then used various internal tricks to still make things work. With Vaadin 10, we are instead relying on the standard way of handling static files, which might cause some surprises for anyone who is used to previous versons.

When you deploy an application as a WAR file, the static resources should be in the root of the WAR file. With the default Maven directory setup, this means that the files should be inside src/main/webapp/.

When you deploy as a JAR file, the static resources needs to be inside META-INF/resources/ in that JAR file. In the Maven world, this means that the files go to src/main/resources/META-INF/resources/.

If you take a working application and change the packaging method, you also need to move the resource files accordingly.

ilya-ershov commented 6 years ago

Thank you, I beleive I've already tried your solution, and that wasn't working. May be I need to revisit it at spare time because I dont have evidences right now. Edit: can confirm that it works now.

So actually yes, if the issues are not connected to each other, then ticket is about the second one. It is definitely a bug, because it doesn't work on Win, though works on Linux.

ilya-ershov commented 6 years ago

Okay I've found that issue is hidden in spring-boot org.springframework.boot.web.servlet.server.StaticResourceJars#getUrls It sees only one pathing jar and nothing more. It doesnt try to locate manifest inside, to locate real dependencies.

pekam commented 6 years ago

Hi @ilya-ershov!

Okay I've found that issue is hidden in spring-boot

If it's a spring-boot issue, do you mind if we close this one? Or was there still something related to Vaadin in this ticket?

ilya-ershov commented 6 years ago

I dont mind! You can close it