Correspondence of getErrorPath of deprecated ErrorController

Introduction

Summary article of this issues / 19844

Overview

From Spring Boot 2.3.0 or later GetErrorPath of ╩╗ErrorController` used for error handling such as 404 has been deprecated.

ErrorController.java


	/**
	 * The return value from this method is not used; the property `server.error.path`
	 * must be set to override the default error page path.
	 * @return the error path
	 * @deprecated since 2.3.0 in favor of setting the property `server.error.path`
	 */
	@Deprecated
	String getErrorPath();

problem

I get a warning at compile time. As described in Javadoc in the first place, there is no particular point in overriding the corresponding method. (Because the setting contents of server.error.path are valid)

ErrorController implementation class


    @Override
    public String getErrorPath() {
        return null;
    }

Correspondence

Target of correction

If you are worried about the warning, add @Deprecated to remove the warning.

ErrorController implementation class


    @Deprecated
    @Override
    public String getErrorPath() {
        return null;
    }

Supplement

Note that the default BasicErrorController will be enabled if ErrorController is not implemented.

ErrorMvcAutoConfiguration.java


	@Bean
	@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
	public BasicErrorController basicErrorController(ErrorAttributes errorAttributes,
			ObjectProvider<ErrorViewResolver> errorViewResolvers) {
		return new BasicErrorController(errorAttributes, this.serverProperties.getError(),
				errorViewResolvers.orderedStream().collect(Collectors.toList()));
	}

Recommended Posts

Correspondence of getErrorPath of deprecated ErrorController