By dropping the redirectUrl statement and just use a view directly. Placing a 404.html in your error-folder and using that with Thymeleaf directly in your errorHandler404 function.
If the user needs to be able to control the text on that page, perhaps that page should be placed inside Admin as content and be fetched when rendering response to the error.
A small comment to this - Ideally you would make your error page as lean as possible, and avoid depending on other functionality. I.e. what if the repository is currently failing and you try to fetch content from it in order to display the error page caused by this failure in the first place?
Error pages should normally not show up, and preferably be 100% based on raw assets and the code in the error handler. If you need text there, simply add it in your application code.
You cannot redirect and set a 404 status at the same time. This is because an HTTP redirect is a response with status 3xx, plus the response header “Location” with the target URL to redirect to.
What you could do is redirect to the page you want and pass an extra parameter indicating that the page controller should set 404 in the response.