Java – Trailing slash is not inserted in Spring Boot application

javaspringspring-boottomcat

Tomcat in Spring Boot is not inserting the trailing slash after context name at URL.

It should be done automatically by server case it was not specified.

Example:
/user would be changed to /user/ by server

Does anyone have any idea how to enable it?

Thanks

Best Answer

It is not supposed to insert the trailing slash.

It only does that in the case of the contextRoot (which in a Spring Boot application is usally /, so going to http://your.server.here:8080 will redirect to http://your.server.here:8080/)

What is your use case for the redirects?

In case you want this functionality, it should be quite trivial to add a filter that would do the redirects for you.

Check out the answers on this question for how to do it Spring MVC: urls with trailing slash redirection