Ditscheridou
Ditscheridou

Reputation: 391

Vaadin Flow &Spring Boot cant find resource via servlet context

Im running in an issue with the new Vaadin Flow issue which makes me crazy the last days, so i hope you guys can help me.

Technologies i use:

  1. Vaadin Flow Beta 8
  2. Spring Boot 2.0.1.RELEASE
  3. Embedded Tomcat
  4. Maven as build tool

Project layout:

Parent project
|
|-api
|
|–common
|
|-webapp

Basic situation: i have a monolithic Vaadin Flow application which now i want to cut in 3 pieces: webapp, common and api. Before this split, everything works fine.

Current situation: When i try to navigate to localhost:8080/ i got this following error:

Caused by: java.lang.IllegalStateException: Can't find resource 'frontend://styles/landing.html' via the servlet context
at com.vaadin.flow.component.polymertemplate.DefaultTemplateParser.getTemplateContent(DefaultTemplateParser.java:111) ~[flow-server-1.0.0.beta7.jar:na]
at com.vaadin.flow.component.polymertemplate.TemplateDataAnalyzer.parseTemplate(TemplateDataAnalyzer.java:180) ~[flow-server-1.0.0.beta7.jar:na]
at com.vaadin.flow.component.polymertemplate.TemplateInitializer.<init>(TemplateInitializer.java:91) ~[flow-server-1.0.0.beta7.jar:na]
at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:78) ~[flow-server-1.0.0.beta7.jar:na]
at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:93) ~[flow-server-1.0.0.beta7.jar:na]
at com.flatNow.ui.common.abstracts.AbstractView.<init>(AbstractView.java:6) ~[classes/:na]
at com.flatNow.ui.landing.LandingView.<init>(LandingView.java:23) ~[classes/:na]
at com.flatNow.ui.landing.LandingPresenter.<init>(LandingPresenter.java:18) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_162]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_162]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_162]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170) ~[spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
... 109 common frames omitted

The corresponding View class is:

@Getter
@Tag("welcome-view")
@HtmlImport("styles/landing.html")
class LandingView extends AbstractView<TemplateModel> {
}

My resources are laying under src/main/resources, there are the folder frontend and assets.

I try the following things things:
Change the htmlImport to context://frontend/styles/landing.html , /frontend/styles/landing.html , ../frontend/styles/landing.html
https://github.com/vaadin/skeleton-starter-flow-spring/issues/28

The weird part is, that i've tried to run the project in Eclipse and it worked out of the box. No issues.

I hope you can help me guys, if i've missing something please point it out!

Upvotes: 1

Views: 1503

Answers (1)

Artur Signell
Artur Signell

Reputation: 1812

The HTML resources are not classpath resources but static web resources. The frontend:// protocol maps to context://frontend (in development mode), which in turn maps to the context root +”/frontend”, so you should place your static files so that they can be loaded by the browser using e.g. http://localhost:8080/frontend/styles/landing.html.

Now with a normal war style project, this would be src/main/webapp/frontend/styles/landing.html. If the resources are in another jar file, then the standard location would be /META-INF/resources/frontend/styles/landing.html. Spring Boot has some other/additional ways to define static files and these should be ok too as long as they can be found through the servlet context, as expected for all static resources.

If you run inside Eclipse, things might work slightly differently as Eclipse does not package and use other projects as jar files but instead use the other project files directly

Upvotes: 2

Related Questions