如何在Spring Boot上替换ErrorController不推荐使用的功能?

问题描述 投票:0回答:1

在Spring Boot上具有自定义错误控制器:

package com.example.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.boot.web.servlet.error.ErrorController;
import javax.servlet.http.HttpServletRequest;


@Controller
public class CustomErrorController implements ErrorController
{
    @RequestMapping("/error")
    public String handleError(HttpServletRequest request)
    {
        ...
    }

    @Override
    public String getErrorPath()
    {
        return "/error";
    }
}

但是,当编译时说:getErrorPath() in ErrorController has been deprecated。好的,我找到了信息:使用server.error.path属性。好的,在application.properties中添加它并删除该函数,但是现在说:CustomErrorController is not abstract and does not override abstract method getErrorPath() in ErrorController,'需要不推荐使用的函数吗?。

如何制作自定义错误控制器?ErrorController要求getErrorPath,但已弃用,正确的选择是什么?。>

在Spring Boot上具有自定义错误控制器:com.example.controllers包;导入org.springframework.stereotype.Controller;导入org.springframework.web.bind.annotation.RequestMapping; ...

spring-boot deprecated
1个回答
0
投票

@ControllerAdvice注释

© www.soinside.com 2019 - 2024. All rights reserved.