1. 添加对Redis连接失败异常的捕获,尝试分析Redis连接失败原因
2. 在配置文件dev和test中添加Redis密码
(cherry picked from commit 9d8c1488c9)
This commit is contained in:
@@ -5,11 +5,13 @@ import cn.dev33.satoken.exception.SaTokenException;
|
|||||||
import com.realtime.protection.configuration.response.ResponseResult;
|
import com.realtime.protection.configuration.response.ResponseResult;
|
||||||
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
import com.realtime.protection.configuration.utils.enums.StateEnum;
|
||||||
import com.realtime.protection.server.task.status.StateChangeService;
|
import com.realtime.protection.server.task.status.StateChangeService;
|
||||||
|
import io.lettuce.core.RedisConnectionException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.ibatis.exceptions.PersistenceException;
|
import org.apache.ibatis.exceptions.PersistenceException;
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
|
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@@ -112,4 +114,11 @@ public class GlobalExceptionHandler {
|
|||||||
log.error(responseResult.getMessage());
|
log.error(responseResult.getMessage());
|
||||||
return responseResult;
|
return responseResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Order(2)
|
||||||
|
@ExceptionHandler(value = RedisConnectionFailureException.class)
|
||||||
|
public ResponseResult handleRedisConnectionException(RedisConnectionFailureException e) {
|
||||||
|
log.warn("Redis连接失败,具体原因:{}", e.getCause().getMessage());
|
||||||
|
return ResponseResult.error().setMessage("Redis连接失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class TaskController implements TaskControllerApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!errorIds.isEmpty()) {
|
if (!errorIds.isEmpty()) {
|
||||||
return new ResponseResult(400, "id or status is invalid")
|
return ResponseResult.invalid()
|
||||||
.setData("tasks_id", errorIds)
|
.setData("tasks_id", errorIds)
|
||||||
.setData("success", false);
|
.setData("success", false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ spring:
|
|||||||
max-idle: 5
|
max-idle: 5
|
||||||
min-idle: 1
|
min-idle: 1
|
||||||
connect-timeout: 1000
|
connect-timeout: 1000
|
||||||
|
password: aiihhbfcsy123!@#
|
||||||
|
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
|
|||||||
Reference in New Issue
Block a user