In Wildfly, "/" is rewritten to "/index.html", bypassing RequestMapping ("/")
I am migrating a Spring MVC application from JBoss 7.1.1 to Wildfly 8.1, which required (encouraged?) Me to use the new "underow" module instead of the old "web module". Everything goes straight, except that it now asks for " /
" which is used to call the controller method annotated with @RequestMapping("/")
, no longer reaches the controller method. Instead, it seems that such requests are immediately rewritten (not redirected) to " /index.html
". Since I don't have (and never need) such a file, all requests for " /
" now generate 404 errors.
Interestingly, all other @RequestMapping
-annotated controller methods continue to function normally.
Here is the relevant snippet from my file standalone.xml
.
<subsystem xmlns="urn:jboss:domain:undertow:1.1">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" max-post-size="4194304"/>
<host name="default-host" alias="localhost">
</host>
</server>
<servlet-container name="default">
<jsp-config development="true"/>
</servlet-container>
</subsystem>
I suspect that when the definition subsystem
for Wildfly's lookup module does not explicitly declare handler
, Wildfly uses a default handler file
that might be responsible for URL rewriting, but I'm not sure from that.
The Undertow project handler documentation that Wildfly is based on indicates support for the Redirect handler. I thought about using this to get around the unexpected "/" rewrite, but I am not clear if the Wildfly module supports the module, and if so, how to configure it in standalone.xml
. However, even if I were able to, I would have thought it would look like a hack, and I'd rather go to the root of the problem (instead of a pun).
There is a lot of SO questions, describing the disappointing behavior RequestMapping("/")
, and many of the answers that involve the use of other ways (eg ""
, "/index"
etc.), but do not forget: the existing (unchanged) code works fine in JBoss 7.1.1, (In addition, no one of these questions does not mention Wildfly, which is probably a key consideration for this question.) However, I experimented with various suggestions and did not come across anywhere. The url seems to be rewritten before it ever reaches the dispatcher servlet.
So, in conclusion, my question is:
How can I get my Spring MVC application
RequestMapping("/")
to run in Wildfly 8.1 like in JBoss 7.1.1?
source to share
In Wildfly, if yours web.xml
does not have an element <welcome-file-list>
, then it is presented to you as if you configured it like this:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
With this default configuration, when Wildfly receives a request for " /
", the path is automatically overwritten as index.html
. This path will not match the controller method annotated with RequestMapping("/")
.
JBoss 7 appears to behave differently, perhaps only referencing the greeter file list after it couldn't find the appropriate servlet.
Regardless of the reason, you can work around the new behavior by explicitly defining your own list of greetings files and including an <welcome-file>
empty greeter file as the last element :
<welcome-file></welcome-file>
This allows Wildfly to be rewritten " /
" as " /
" so that the request " /
" can be processed by the servlet manager (assuming it is url-pattern
set to a value /
). The servlet manager will then call the controller method annotated with RequestMapping("/")
.
source to share