我的Spring Boot
应用程序在IIS Server
上运行,生成自定义错误页面,用于在标头处查找错误代码401
。我想禁用它。响应数据中不应有自定义错误页面。 Apache server
中存在默认行为。虽然IIS Server
可以配置为阻止为远程请求生成自定义错误页面,但我希望从我的应用程序配置它(Web配置点可能是)。是Spring
有可能吗?
答案 0 :(得分:0)
在你的web.xml中添加:
<error-page>
<error-code>401</error-code>
<location>/errors/unauthorised</location>
</error-page>
然后添加一个这样的控制器:
@Controller
@RequestMapping("/errors")
public class ApplicationExceptionHandler {
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@RequestMapping("unauthorised")
public ModelAndView unauthorizedError(){
return new ModelAndView("errors/error.jsp");
}
}
答案 1 :(得分:0)
将web.config
文件添加到您应用的网络应用目录(app/src/main/webapp)
。 web.config
文件应包含:
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" existingResponse="Auto" />
</system.webServer>
</configuration>
这会导致IIS web server
将错误模式设置为'Detailed'
,这会阻止生成自定义错误页面。