Pages cannot be displayed when deploying Vaadin 12 war on Tomcat server

Hello everyone,

I am facing two problems between running Vaadin 12 with Spring boot 2.0.6 in Eclipse Photon IDE and in a war on Tomcat 8.5 server:

  • when requesting home page it comes up with this Exception Caused by: java.lang.IllegalArgumentException: Unable to create an instance of 'myProject.HomePage'. Make sure the class has a public no-arg constructor.
  • I found some workaround to access login page (which does not resolve the first problem) but it displays a blank page because the two resources cannot be found http://contextRoot/frontend/styles/shared-styles.html and http://contextRoot/frontend/src/views/login/login-view.html. These two resources are located in src\main\resources\static folder.
    • If I deploy my project as a jar, ok it is working but css files are not read
    • If I give an Autowire argument to LoginView, displayed Exception for HomePage is not thrown

For information:

  • Everything goes fine while my project is run from IDE
  • Everything goes fine if my project takes Vaadin 10 instead of 12
  • My log displays this message: INFOS: 2 Spring WebApplicationInitializers detected on classpath
    Does anyone have a clue for this?

Thank you for reading.

I am experiencing a similar issue where sometimes (in average about every second time I run the app) the static resources in the frontend folder are not available. When this happens, the login page is blank. See attachment ‘no-static-resources.png’ for a screenshot of the dev-tool when this happens.

Usually (not always) when I then stop the app, clean and install it again and re-run it, then it has again the static resources - see attachment ‘has-static-resources.png’.

I have no idea what is the cause for this and it is causing real headache!
I do not use tomcat, and I do not have an exception about missing no-arg constructors.

I import files from the frontend folder using this path syntax:

@HtmlImport("src/views/login-view.html")
public class LoginView ....

Edit: I use websphere/liberty for local runs. my frontend folder is in src/main/webapp and not in src/main/resources/static because that has never worked for me.

17493161.png
17493164.png

Hi Kaspar Scherrer, thank you for your reply.

I tried your technic:

  • run application from Tomcat
  • clean Tomcat
  • Install it
  • Re-run it

The magic does not work…
What kind of application server do you use?

I was not trying to give you a solution - Since I have the same or a similar issue I just wanted to provide more information about it from my perspective :wink:

Update: I do no longer experience this issue anymore, the static files are now always available to me.

I am not exactly sure what it was that fixed it, but my guess is that it has to do with the SecurityConfiguration that I have edited for my project this week. More explicitely, I added the line .requestMatchers(SecurityUtils::isFrameworkInternalRequest).permitAll() in the method override of configure(HttpSecurity http), and added a whole method override for configure(WebSecurity web) that I copied from [this forum post]
(https://vaadin.com/forum/thread/17475153/17476082).

I did it in my project too, but the 2 problmes still remain… Thank you for sharing.

I have just spotted my log displays this message: INFOS: 2 Spring WebApplicationInitializers detected on classpath

Would it be linked to my situation?

This worked for me [forum]
(https://vaadin.com/forum/thread/17168149/autowire-by-constructor-fails)

Application.java has to extend SpringBootServletInitializer:

public class Application extends SpringBootServletInitializer {
 // ...
}

Hello Alvaro Jose Garcia Cohen, I made it too but it does not work.

I think the real problem is the application cannot see files in static folder.
I implemented .requestMatchers(SecurityUtils::isFrameworkInternalRequest).permitAll().

I tried to start bakery project in tomcat 9 and it is absolutely the same.

Maybe production mode is mandatory?

Finally I found a workaround: Vaadin 12 has not copied files in static folder into application root.
I moved them and it goes fine.

Is there anything I missed with these files?
In Vaadin 10 moving worked fine.

Steeve Spatafora:
Finally I found a workaround: Vaadin 12 has not copied files in static folder into application root.
I moved them and it goes fine.

Is there anything I missed with these files?
In Vaadin 10 moving worked fine.

Hi Steeve!

Can you tell me what files you moved, and to what location?

Thanks!

I moved every file in app-root/WEB-INF/classes/static into app-root.
For example: the frontend folder.

Thanks Steeve! it works for me :slight_smile:

Steeve Spatafora:
I moved every file in app-root/WEB-INF/classes/static into app-root.
For example: the frontend folder.

Hi Steeve, after you moved the frontend foolder in the path: app-root/WEB-INF/classes/static, how you call it in view?
Because for me @StyleSheet(“fronted://nameRes…”) doesn’t work

Hello Vincenzo,

we put all files from static folder into webapp in our IDE before deployment.
Then we call them, from your example, with @StyleSheet(“context://fronted/name”)