The approach I would probably use would be to actually handle it in a Controller:
@Controller
public class RobotsTxtController {
@RequestMapping("/robots.txt")
@ResponseStatus(HttpStatus.NOT_FOUND)
public void robotsTxt() {}
}
You could have the method return a view name if you want an actual page to appear.
This way, it's an actual "page" and not handled by your normal 404 process, but the @ResponseStatus
makes it return as a 404.