java springboot 配置 404页面

java springboot 配置 404页面,第1张

java springboot 配置 404页面

比较简单,直接上代码了。这里仅作记录以免后面需要用的时候忘了

package com.yutangcun.blog.config;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class ErrorPageConfig implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        registry.addErrorPages(
        	new ErrorPage(HttpStatus.NOT_FOUND, "/page/404.html"), 
        	new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/page/500.html")
        );
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5695164.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存