-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
properties bound from request header to data class #34125
Comments
Have you tried filtering this property in the binder as explained here? |
@bclozel I added the property override fun doFilter(request: ServletRequest?, response: ServletResponse?, chain: FilterChain) {
val httpServletRequest = request as HttpServletRequest
// something ...
request.setHeader(Constant.BU, "$bu")
// something ...
} But in the old version, there were no issues; I have always used it this way. |
@664623107 that is not what I was suggesting. Please try the code snippet suggested here, configuring the binder to ignore the "bu" header. Here's a class you can copy to your project that will ignore all header values. Let us know how this works for you. import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;
@ControllerAdvice
public class MyControllerAdvice {
@InitBinder
public void initBinder(ExtendedServletRequestDataBinder binder) {
binder.addHeaderPredicate(header -> false);
}
} |
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;
@ControllerAdvice
public class MyControllerAdvice {
@InitBinder
public void initBinder(ExtendedServletRequestDataBinder binder) {
binder.addHeaderPredicate(header -> false);
}
} @bclozel Thanks,It worked. |
Thanks for letting us know. I think this is due to #34073, so not a bug. Your DTO class takes this argument in its constructor, which is a pretty strong signal for the binder to do the binding. I'll leave this opened for now to let Rossen comment on this, but I suspect that binding constructor arguments is the expected behavior here. |
I found that when using Spring Boot 3.4.1, this version places the properties from the header into the request when handling web requests.
There is a property bu in the header of request.
code:
request:
in 3.4.1:
in <=3.4.0
The text was updated successfully, but these errors were encountered: