首先在resource目录下创建一个error的目录,properties配置文件放在error目录中,如下图所示:
读取
@ControllerAdvice
@Slf4j
public class DefaultRestControllerExceptionHandler {
private Properties httpStatusErrorMap;
@PostConstruct
private void initHttpStatusErrorMap() {
httpStatusErrorMap = new Properties();
try {
InputStream in = DefaultRestControllerExceptionHandler.class.getResourceAsStream("/error/httpStatus.properties");
if (in != null) {
Properties tempProperties = new Properties();
tempProperties.load(in);
httpStatusErrorMap.putAll(tempProperties);
}
} catch (IOException e) {
log.error("{}",e.getMessage(), e.fillInStackTrace());
throw new SystemException("IOException", e);
}
}
}