Cannot ignore default model on redirect after upgrading Spring Boot
See original GitHub issueI’ve upgraded Spring Boot from 1.3.5 to 1.5.2 in this commit https://github.com/sorra/sage-system/commit/aa67c6f67a8ada51940c3dbf1c22241caaac2b78
Then when I return redirect:$someURL in a controller, it adds model attributes to the URL, then the URL is too long and fails.
In 1.3.5 there are no model attributes on redirect, but in 1.5.2 that behavior is broken.
I’ve read 1.4 and 1.5 release notes but got no information.
Even if I add explicit spring.mvc.ignore-default-model-on-redirect=true to application.properties, it still doesn’t work.
-
Note 1: I also changed the inheritance of my
Applicationclass becauseWebMvcAutoConfigurationAdapterhas changed a lot:[Kotlin code]
@SpringBootApplication
-open class Application : WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter() {
+@EnableWebMvc
+class Application : WebMvcConfigurerAdapter() {
- Note 2: My default model attributes are added via a
@ControllerAdvicewith@ModelAttribute
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Spring automatic adds model param to url - Stack Overflow
When upgrading to spring-mvc-4.0.xsd, you should replace enableMatrixVariables and ignoreDefaultModelOnRedirect with enable-matrix-variables and ignore-default- ...
Read more >How to make spring not to add all model attributes to a redirect ...
[Solved]-How to make spring not to add all model attributes to a redirect URL?-Spring MVC ... Add ignore-default-model-on-redirect="true" to your <mvc:annotation- ...
Read more >17. Web MVC framework - Spring
The RedirectView issues an HttpServletResponse.sendRedirect() call that returns to the client browser as an HTTP redirect. By default all model attributes are ...
Read more >Spring Boot/MVC: Prevent Spring MVC @ModelAttribute ...
This was happening when we used @ModelAttribute variables and performed redirects. After some searchi it turned out that this is the default ......
Read more >Top 10 Most Common Spring Framework Mistakes - Toptal
In this article we'll cover some of the more common mistakes in Spring, specifically oriented towards web applications and Spring Boot. As Spring...
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 Free
Top 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

I couldn’t reproduce this issue with Spring Boot 1.4.6. Creating a new project with start.spring.io and adding the following classes shows that the feature is working as expected:
The only way to reproduce the behavior you’re describing is to set the dedicated property to
spring.mvc.ignore-default-model-on-redirect=false.I believe you’re both adding
@EnableWebMvcto your application configuration. Using@EnableWebMvcgives you full control over Spring MVC and disables Boot’s auto-configuration for that. This explains why Boot’s defaults and properties for MVC aren’t working anymore. There are many other ways to customize your MVC configuration with Boot.Note that extending/overriding Spring Boot’s auto-configuration is not a good idea, for the very reason you’re experiencing: this is very brittle and a subtle change in Boot might break your application.
If I missed something here, please create a simple repro project from start.spring.io so I can investigate.
Thanks!
@bclozel I tried a clean project (Spring Boot 1.4.5 for comparison) and it works exactly like you described it/it should work. 👍
We use
@EnableWebMvc, so it is very possible that this behavior appears in connection with this specific annotation.Thanks for the help and the time invested into this issue!