I'm using Spring MVC with Thymeleaf also. Mine is a combo of a couple of answers that considers both cases. Changing return to void probably works; i was doing that in another method, but if you need to return a String because you need to return a name of a view/web page to go to next, it is now working for me if I return null; at the end of the method.
So staying with return of String:
I can do: return "redirect:/login"; if needed
before I write to outStream.
but if I do write to outStream, which works, I get an error,
I cannot return a string, even "" after that
but if I return null; after writing to outputStream that works.
spring boot 3.3