Skip to content

Commit

Permalink
默认关闭静态资源,处理404返回报文
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutaoo committed Mar 6, 2024
1 parent c2a7299 commit ede8d4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#==============springboot相关配置===============#
spring.sleuth.sampler.probability=1
spring.web.resources.add-mappings=false
spring.mvc.format.date-time=yyyy-MM-dd HH:mm:ss
spring.mvc.format.date=yyyy-MM-dd
spring.servlet.multipart.max-request-size=2MB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public enum SystemErrorType implements ErrorType {
* 系统繁忙,限流时
*/
SYSTEM_BUSY("000001", "系统繁忙,请稍候再试"),
/**
* 未找到该资源
*/
RESOURCE_NOT_FOUND("000404", "资源未找到"),
/**
* 网关转发时未找到该服务
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
* 默认全局异常处理类
Expand Down Expand Up @@ -56,6 +57,13 @@ public Result notSupportedMethodException(HttpRequestMethodNotSupportedException
return Result.fail(SystemErrorType.METHOD_NOT_SUPPORTED);
}

@ExceptionHandler(value = {NoHandlerFoundException.class})
@ResponseStatus(HttpStatus.NOT_FOUND)
public Result noHandlerFoundException(NoHandlerFoundException ex) {
log.warn("No static resource exception:{}", ex.getMessage());
return Result.fail(SystemErrorType.RESOURCE_NOT_FOUND, ex.getMessage());
}

@ExceptionHandler(value = {HttpMediaTypeNotSupportedException.class})
@ResponseStatus(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
public Result notSupportedMethodException(HttpMediaTypeNotSupportedException ex) {
Expand Down

0 comments on commit ede8d4a

Please sign in to comment.