springboot自定義錯誤頁面

2021-08-20 13:43:21 字數 961 閱讀 3014

@controller

public

class

baseerrorcontroller

implements

errorcontroller

public string error()

}

方法二:新增自定義的錯誤頁面
2.1 html靜態頁面:在resources/public/error/ 下定義

如新增404頁面: resources/public/error/404.html頁面,中文注意頁面編碼

2.2 模板引擎頁面:在templates/error/下定義

如新增5xx頁面: templates/error/5xx.ftl

注:templates/error/ 這個的優先順序比較 resources/public/error/高

方法三:使用註解@controlleradvice
/**

* 統一異常處理

/*** 統一異常處理

SpringBoot自定義錯誤頁面

在springboot中,除了springboot預設的錯誤頁面外,我們也可以自定義頁面,當然了,我們首先需要新增依賴 org.springframework.bootgroupid spring boot starter thymeleafartifactid dependency 除了thyme...

Spring Boot 自定義錯誤頁面

使用spring boot構建的web應用可以很方便的打成jar包發布,也可以打成war包發布到應用伺服器中。自定義錯誤頁面在這兩種發布方式下是不一樣的。建立spring boot專案,預設打包方式是jar,內部使用內嵌tomcat等servlet容器 最簡單的方式是直接在resources tem...

自定義Spring Boot裝配

spring boot自動配置會嘗試根據新增的jar依賴項自動配置spring應用程式。使用 componentscan 查詢您的bean 和使用 autowired 進行建構函式注入 自動配置類使用 conditionalonclass和 conditionalo singbean注釋,condi...