Spring MVC listening on / breaks vaadin application
See original GitHub issueTo make sure we can quickly validate and fix the bug, please provide as much as possible of the following information:
- Description of the bug
- Minimal reproducible example
- Expected behavior
- Actual behavior
Description of the Bug
If you create a Spring Boot Application with Vaadin 10 (flow) with a Spring MVC Rest Controller listening with GET on “/*”, vaadin wont work. Changing vaadin.urlMapping lead to another error/bug.
How to reproduce
- Create a blank Spring Boot Application with Vaadin 10.0.1
- Create a Rest Controller (Spring MVC)
@RequestMapping(produces = "text/html")
public class IssueReproduceVaadin {
@RequestMapping(value = {""}, method = RequestMethod.GET)
public String demo() {
return "vaadin broke....";
}
}
- Create a Vaadin View with @Push and @Route(“admin”) or something like this and a Button …
@Push
@Route("admin")
public class BaseLayout extends VerticalLayout {
public BaseLayout() {
Button button = new Button("Broke the App :)");
button.addClickListener(buttonClickEvent -> {
System.out.println("do something");
});
add(button);
}
}
- Open the Application at http://localhost:8080/admin
- Profit?
Hint: I tried to change the vaadin.urlMapping to another value, but after this, the UI cannot find the files in frontend/bower_components/...
…
Expected behaviour
The Application works just fine
Actual behaviour
The application (ui) is responding with “Server Connection lost” and the log is spammed with “Request method ‘POST’ not supported”
What should be possible
- vaadin.urlMapping works fine
- change the POST Endpoint for vaadin from /?v… to another endpoint
Regards SeaLife
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Working with Spring MVC | Integrations | Flow | Vaadin 14 Docs
In this section we cover how to use Vaadin with Spring MVC. Spring MVC is the original Spring web framework built on the...
Read more >How to Rock your Web Apps with Spring and Vaadin - YouTube
There is an alternative to creating page based Spring MVC UIs by hand. Using Spring Initializr and Vaadin you can add rocket fuel...
Read more >Securing Vaadin apps with Spring Security and Keycloak ...
In this webinar, you will learn how to secure your Spring Boot-based Vaadin apps from common threats. We will show you how to...
Read more >Vaadin 22 with web.xml and Spring - Stack Overflow
In my applicationContext.xml file, I'm using <context:component-scan> to find all of the various Vaadin Spring config beans, ...
Read more >What I wish I had known about single page applications
Every response back from the server is the full HTML document required to render a web page. A single-page app breaks this paradigm....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you Giovanni for absolutely correct answer. That’s the answer which I should have written but didn’t find the proper words.
Spring Flow is just one one a lot of Flow related projects : Flow, a number of individual components, various integrations including Spring , CDI , etc. Each this project has quite many issues. So we just have no resources to check everything especially summer time when at least a half of team is on vacation. We are working on prioritized tickets at the moment. This one is not more important than any other ticket.
If you want to get fixes something ASAP then you may use your support subscription and mark bug as BFP. In this case it will be prioritized and we start to work on it ASAP.
Now about this ticket.
This is not a bug at all. Vaadin servlet listens by default root URL “/". There is always a servlet under the hood even if you don’t see it and use
@Route
. In your specific case you use@Route("admin")
and expect that"/"
path is not occupied by anything. It doesn’t work in this way. As I said there is always a servlet which is mapped to the URL. By default it’s "/”. You have overriden this URL by you REST service method.So of course it doesn’t work because you have overriden Vaadin servlet mapping. In similar way you may have
@Route("")
and expect that it works with your REST service.@Route
is not a standalone mapping as it’s in REST . It works only under Vaadin servlet.So this is not a bug at all.
If you want to get Vaadin working then there are two options:
And for the latter there is
vaadin.urlMapping
property.And yes, in this case everything in frontend is not mapped automatically for you. This is known issue (we don’t even consider this is as a bug).
This is how things work. You need to do additional config to be able to get
frontend
working with your Vaadin appication in case you change the default mapping.I personally think that this is really a bad limitation and there is a ticket about it to make it possible work out of the box: https://github.com/vaadin/flow/issues/3600
But what you should do is: create a servlet which extends
VaadinServlet
with"/frontend"
mapping. This additional servlet will handle webjar URLs and solve your issue.I’m closing this ticket since the original issue is not a bug at all. And the issue with
vaadin.urlMapping
is covered by another ticket.One more thing: please use correct repository for the issues. This ticket is about Spring and should have been made in vaadin/spring repo.
Hey,
just discovered, if
vaadin.urlMapping
is set, everthing in frontend is not mapped.For example, using the urlMapping
/ui/
you can open the UI on...:8080/ui/
but you cant access the frontend resources… Not even with...:8080/ui/frontend/...
its simply not there.Regards SeaLife