修改依赖
This commit is contained in:
parent
6c8bfc651b
commit
f7c036795d
16
pom.xml
16
pom.xml
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<version>2.3.12.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>cn.zyjblogs</groupId>
|
||||
@ -25,6 +25,7 @@
|
||||
<zyjblogs.version>1.0-SNAPSHOT</zyjblogs.version>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<compler.maven.plugin.version>2.3.12.RELEASE</compler.maven.plugin.version>
|
||||
<!-- spring-cloud版本配置 -->
|
||||
<spring-cloud.version>Hoxton.SR12</spring-cloud.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
@ -204,11 +205,6 @@
|
||||
<artifactId>commons-crypto</artifactId>
|
||||
<version>${commons-crypto.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ma.glasnost.orika</groupId>
|
||||
<artifactId>orika-core</artifactId>
|
||||
<version>${orika-core.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-oauth2-authorization-server -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.security</groupId>-->
|
||||
@ -260,6 +256,14 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${compler.maven.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<artifactId>zyjblogs-common-spring-boot-starter</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
@ -76,6 +76,7 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${compler.maven.plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.zyjblogs.starter.common.entity.response;
|
||||
|
||||
public enum ResponseStatus {
|
||||
public enum HttpCode {
|
||||
CONTINUE(100, "Continue"),
|
||||
SWITCHING_PROTOCOLS(101, "Switching Protocols"),
|
||||
PROCESSING(102, "Processing"),
|
||||
@ -87,7 +87,7 @@ public enum ResponseStatus {
|
||||
private final int value;
|
||||
private final String reasonPhrase;
|
||||
|
||||
private ResponseStatus(int value, String reasonPhrase) {
|
||||
private HttpCode(int value, String reasonPhrase) {
|
||||
this.value = value;
|
||||
this.reasonPhrase = reasonPhrase;
|
||||
}
|
||||
@ -101,27 +101,27 @@ public enum ResponseStatus {
|
||||
}
|
||||
|
||||
public Series series() {
|
||||
return ResponseStatus.Series.valueOf(this);
|
||||
return HttpCode.Series.valueOf(this);
|
||||
}
|
||||
|
||||
public boolean is1xxInformational() {
|
||||
return this.series() == ResponseStatus.Series.INFORMATIONAL;
|
||||
return this.series() == HttpCode.Series.INFORMATIONAL;
|
||||
}
|
||||
|
||||
public boolean is2xxSuccessful() {
|
||||
return this.series() == ResponseStatus.Series.SUCCESSFUL;
|
||||
return this.series() == HttpCode.Series.SUCCESSFUL;
|
||||
}
|
||||
|
||||
public boolean is3xxRedirection() {
|
||||
return this.series() == ResponseStatus.Series.REDIRECTION;
|
||||
return this.series() == HttpCode.Series.REDIRECTION;
|
||||
}
|
||||
|
||||
public boolean is4xxClientError() {
|
||||
return this.series() == ResponseStatus.Series.CLIENT_ERROR;
|
||||
return this.series() == HttpCode.Series.CLIENT_ERROR;
|
||||
}
|
||||
|
||||
public boolean is5xxServerError() {
|
||||
return this.series() == ResponseStatus.Series.SERVER_ERROR;
|
||||
return this.series() == HttpCode.Series.SERVER_ERROR;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
@ -132,8 +132,8 @@ public enum ResponseStatus {
|
||||
return this.value + " " + this.name();
|
||||
}
|
||||
|
||||
public static ResponseStatus valueOf(int statusCode) {
|
||||
ResponseStatus status = resolve(statusCode);
|
||||
public static HttpCode valueOf(int statusCode) {
|
||||
HttpCode status = resolve(statusCode);
|
||||
if (status == null) {
|
||||
throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
|
||||
} else {
|
||||
@ -142,12 +142,12 @@ public enum ResponseStatus {
|
||||
}
|
||||
|
||||
|
||||
public static ResponseStatus resolve(int statusCode) {
|
||||
ResponseStatus[] var1 = values();
|
||||
public static HttpCode resolve(int statusCode) {
|
||||
HttpCode[] var1 = values();
|
||||
int var2 = var1.length;
|
||||
|
||||
for(int var3 = 0; var3 < var2; ++var3) {
|
||||
ResponseStatus status = var1[var3];
|
||||
HttpCode status = var1[var3];
|
||||
if (status.value == statusCode) {
|
||||
return status;
|
||||
}
|
||||
@ -173,7 +173,7 @@ public enum ResponseStatus {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static Series valueOf(ResponseStatus status) {
|
||||
public static Series valueOf(HttpCode status) {
|
||||
return valueOf(status.value);
|
||||
}
|
||||
|
@ -21,21 +21,21 @@ public class ResponseResult {
|
||||
}
|
||||
|
||||
public static <T> ResponseObject<T> success(long total, T data) {
|
||||
return ResponseObject.<T>builder().code(ResponseStatus.OK.value()).msg(ResponseStatus.OK.getReasonPhrase()).count(total).data(data).timestamp(System.currentTimeMillis()).build();
|
||||
return ResponseObject.<T>builder().code(HttpCode.OK.value()).msg(HttpCode.OK.getReasonPhrase()).count(total).data(data).timestamp(System.currentTimeMillis()).build();
|
||||
}
|
||||
public static <T> ResponseObject<T> error(ResponseStatus responseCode, String errorMsg) {
|
||||
public static <T> ResponseObject<T> error(HttpCode responseCode, String errorMsg) {
|
||||
return error(responseCode, responseCode.getReasonPhrase(), errorMsg, 0L, null);
|
||||
}
|
||||
public static <T> ResponseObject<T> error(ResponseStatus responseCode, String errorCode, String errorMsg) {
|
||||
public static <T> ResponseObject<T> error(HttpCode responseCode, String errorCode, String errorMsg) {
|
||||
return error(responseCode, errorCode, errorMsg, 0L, null);
|
||||
}
|
||||
|
||||
public static <T> ResponseObject<T> error(ResponseStatus responseCode, String errorCode, String errorMsg, T data) {
|
||||
public static <T> ResponseObject<T> error(HttpCode responseCode, String errorCode, String errorMsg, T data) {
|
||||
return error(responseCode, errorCode, errorMsg, 1L, data);
|
||||
}
|
||||
|
||||
public static <T> ResponseObject<T> error(ResponseStatus responseCode, String errorCode, String errorMsg, long total, T data) {
|
||||
if (responseCode.value() == ResponseStatus.OK.value()) {
|
||||
public static <T> ResponseObject<T> error(HttpCode responseCode, String errorCode, String errorMsg, long total, T data) {
|
||||
if (responseCode.value() == HttpCode.OK.value()) {
|
||||
throw new IllegalArgumentException("ResponseResult.error方法中的responseCode参数不能是ResponseCode.REQUEST_SUCCESS");
|
||||
} else {
|
||||
return ResponseObject.<T>builder().code(responseCode.value()).errorCode(errorCode).msg(errorMsg == null ? responseCode.getReasonPhrase() : errorMsg).count(total).data(data).timestamp(System.currentTimeMillis()).build();
|
||||
|
@ -10,12 +10,13 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<artifactId>zyjblogs-common-spring-boot-starter</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- Spring 集成 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
@ -61,6 +62,10 @@
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>cn.zyjblogs.pubilc</groupId>
|
||||
<artifactId>zyjblogs-gateway</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@ -40,6 +40,11 @@
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
</dependency>
|
||||
<!-- 集成nacos-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -3,7 +3,7 @@ package cn.zyjblogs.gateway.filter;
|
||||
import cn.zyjblogs.starter.common.entity.constant.HttpHeaderConstant;
|
||||
import cn.zyjblogs.starter.common.entity.response.ResponseObject;
|
||||
import cn.zyjblogs.starter.common.entity.response.ResponseResult;
|
||||
import cn.zyjblogs.starter.common.entity.response.ResponseStatus;
|
||||
import cn.zyjblogs.starter.common.entity.response.HttpCode;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -15,7 +15,6 @@ import org.springframework.cloud.gateway.route.Route;
|
||||
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
@ -66,7 +65,7 @@ public class AuthFilter implements GlobalFilter {
|
||||
}
|
||||
if (isExpired(token)) {
|
||||
log.info("token过期");
|
||||
return getErrorMono(response, ResponseStatus.UNAUTHORIZED, "invalid_token");
|
||||
return getErrorMono(response, HttpCode.UNAUTHORIZED, "invalid_token");
|
||||
}
|
||||
if ("/user/login".equals(path)) {
|
||||
return chain.filter(exchange);
|
||||
@ -131,9 +130,9 @@ public class AuthFilter implements GlobalFilter {
|
||||
* @return reactor.core.publisher.Mono<java.lang.Void>
|
||||
* @date 2021/11/1 17:10
|
||||
*/
|
||||
private Mono<Void> getErrorMono(ServerHttpResponse response, ResponseStatus responseCode, String msg) {
|
||||
private Mono<Void> getErrorMono(ServerHttpResponse response, HttpCode responseCode, String msg) {
|
||||
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
response.setStatusCode(HttpStatus.OK);
|
||||
response.setStatusCode(org.springframework.http.HttpStatus.OK);
|
||||
ResponseObject<Object> responseObject = ResponseResult.error(responseCode, msg);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
byte[] bytes = new byte[0];
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>cn.zyjblogs.pubilc</groupId>
|
||||
<artifactId>zyjblogs-oauth</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@ -22,6 +22,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cn.zyjblogs.oauth.config.security;
|
||||
|
||||
import io.micrometer.core.instrument.util.IOUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -10,7 +10,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.zyjblogs.pubilc</groupId>
|
||||
<artifactId>zyjblogs-rbac</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@ -21,6 +21,11 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
|
@ -10,6 +10,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@ -21,14 +23,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.xiaoymin</groupId>-->
|
||||
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<artifactId>zyjblogs-common-spring-boot-starter</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -48,6 +50,7 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${compler.maven.plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
|
@ -1,110 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package cn.zyjblogs.starter.web.config;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
|
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.ApiKey;
|
||||
import springfox.documentation.service.AuthorizationScope;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.service.SecurityReference;
|
||||
import springfox.documentation.service.SecurityScheme;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider;
|
||||
import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@EnableOpenApi
|
||||
@Configuration
|
||||
@Import({BeanValidatorPluginsConfiguration.class})
|
||||
public class Knife4jAutoConfigurationConfig {
|
||||
@Value("${spring.application.name}")
|
||||
private String applicationName;
|
||||
|
||||
public Knife4jAutoConfigurationConfig() {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) {
|
||||
this.customizeSpringfoxHandlerMappings(this.getHandlerMappings(bean));
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
private <T extends RequestMappingInfoHandlerMapping> void customizeSpringfoxHandlerMappings(List<T> mappings) {
|
||||
List<T> copy = (List)mappings.stream().filter((mapping) -> mapping.getPatternParser() == null).collect(Collectors.toList());
|
||||
mappings.clear();
|
||||
mappings.addAll(copy);
|
||||
}
|
||||
|
||||
private List<RequestMappingInfoHandlerMapping> getHandlerMappings(Object bean) {
|
||||
try {
|
||||
Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings");
|
||||
field.setAccessible(true);
|
||||
return (List)field.get(bean);
|
||||
} catch (IllegalAccessException | IllegalArgumentException var3) {
|
||||
throw new IllegalStateException(var3);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean({"defaultApi"})
|
||||
public Docket defaultApi() {
|
||||
return (new Docket(DocumentationType.SWAGGER_2)).directModelSubstitute(LocalDateTime.class, Date.class).directModelSubstitute(LocalDate.class, String.class).directModelSubstitute(LocalTime.class, String.class).directModelSubstitute(ZonedDateTime.class, String.class).apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.basePackage("cn.zyjblogs")).paths(PathSelectors.any()).build().securityContexts(Lists.newArrayList(new SecurityContext[]{this.securityContext(), this.securityContext()})).securitySchemes(Lists.newArrayList(new SecurityScheme[]{this.apiKey()}));
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return (new ApiInfoBuilder()).title(this.applicationName.toUpperCase() + " RESTFUL APIS").contact(new Contact("zyjblogs", "", "")).version("1.0.0").build();
|
||||
}
|
||||
|
||||
private ApiKey apiKey() {
|
||||
return new ApiKey("BearerToken", "Authorization", "header");
|
||||
}
|
||||
|
||||
private SecurityContext securityContext() {
|
||||
return SecurityContext.builder().securityReferences(this.defaultAuth()).forPaths(PathSelectors.regex("/.*")).build();
|
||||
}
|
||||
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[]{authorizationScope};
|
||||
return Lists.newArrayList(new SecurityReference[]{new SecurityReference("BearerToken", authorizationScopes)});
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package cn.zyjblogs.starter.web.hander;
|
||||
|
||||
import cn.zyjblogs.starter.common.entity.response.HttpCode;
|
||||
import cn.zyjblogs.starter.common.entity.response.ResponseObject;
|
||||
import cn.zyjblogs.starter.common.entity.response.ResponseResult;
|
||||
import cn.zyjblogs.starter.common.exception.AbstractFrameworkException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
private static final String TYPE_MISMATCH = "typeMismatch";
|
||||
|
||||
@ExceptionHandler({NoHandlerFoundException.class})
|
||||
@ResponseStatus(org.springframework.http.HttpStatus.NOT_FOUND)
|
||||
public ResponseObject<?> handleNoHandlerFoundException(NoHandlerFoundException exception) {
|
||||
log.error("NoHandlerFound", exception);
|
||||
String i18nCode = "web_starter_not_found";
|
||||
return ResponseResult.error(HttpCode.NOT_FOUND, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({HttpRequestMethodNotSupportedException.class})
|
||||
public ResponseObject<?> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
|
||||
log.error("HttpRequestMethodNotSupported", exception);
|
||||
String i18nCode = "web_starter_method_not_allowed";
|
||||
return ResponseResult.error(HttpCode.METHOD_NOT_ALLOWED, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({HttpMediaTypeNotSupportedException.class})
|
||||
public ResponseObject<?> handleHttpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException exception) {
|
||||
log.error("HttpMediaTypeNotSupported", exception);
|
||||
String i18nCode = "web_starter_unsupported_media_type";
|
||||
return ResponseResult.error(HttpCode.UNSUPPORTED_MEDIA_TYPE, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({Exception.class})
|
||||
public ResponseObject<?> handleException(Exception exception) {
|
||||
log.error("", exception);
|
||||
String i18nCode = "web_starter_internal_server_error";
|
||||
return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({MethodArgumentTypeMismatchException.class})
|
||||
public ResponseObject<String> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) {
|
||||
String parameterName = exception.getParameter().getParameterName();
|
||||
String i18nCode = "web_starter_property_format_error";
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({ConstraintViolationException.class})
|
||||
public ResponseObject<String> handleConstraintViolationException(ConstraintViolationException exception) {
|
||||
Set<ConstraintViolation<?>> constraintViolations = exception.getConstraintViolations();
|
||||
String i18nCode;
|
||||
if (CollectionUtils.isEmpty(constraintViolations)) {
|
||||
log.warn("全局异常捕获到了ConstraintViolationException,但是没有发现错误", exception);
|
||||
i18nCode = "web_starter_bad_request";
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
} else {
|
||||
i18nCode = ((ConstraintViolation)constraintViolations.stream().findFirst().get()).getMessage();
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
}
|
||||
}
|
||||
|
||||
@ExceptionHandler({MethodArgumentNotValidException.class})
|
||||
public ResponseObject<?> handleMethodArgumentNotValidException(MethodArgumentNotValidException exception) {
|
||||
BindingResult bindingResult = exception.getBindingResult();
|
||||
return this.getByBindingResult(bindingResult);
|
||||
}
|
||||
|
||||
@ExceptionHandler({AbstractFrameworkException.class})
|
||||
public ResponseObject<?> handleFrameworkException(AbstractFrameworkException exception) {
|
||||
log.error("系统异常:", exception);
|
||||
String i18nCode = "web_starter_internal_server_error";
|
||||
return ResponseResult.error(HttpCode.INTERNAL_SERVER_ERROR, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
@ExceptionHandler({BindException.class})
|
||||
public ResponseObject<?> handleBindException(BindException exception) {
|
||||
BindingResult bindingResult = exception.getBindingResult();
|
||||
return this.getByBindingResult(bindingResult);
|
||||
}
|
||||
|
||||
@ExceptionHandler({HttpMessageNotReadableException.class})
|
||||
public ResponseObject<?> handleHttpMessageNotReadableException(HttpMessageNotReadableException exception) {
|
||||
log.error("参数格式不正确", exception);
|
||||
String i18nCode = "web_starter_param_format_error";
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
}
|
||||
|
||||
private ResponseObject<?> getByBindingResult(BindingResult bindingResult) {
|
||||
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
|
||||
if (fieldErrors.isEmpty()) {
|
||||
log.error("捕获到了参数校验错误,但是没有找到错误提示的i18nCode,{}", bindingResult);
|
||||
String i18nCode = "web_starter_parameter_error";
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
} else {
|
||||
FieldError fieldError = (FieldError)fieldErrors.get(0);
|
||||
String i18nCode;
|
||||
if ("typeMismatch".equals(fieldError.getCode())) {
|
||||
i18nCode = "web_starter_property_format_error";
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
} else {
|
||||
i18nCode = fieldError.getDefaultMessage();
|
||||
return ResponseResult.error(HttpCode.BAD_REQUEST, i18nCode, i18nCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
Manifest-Version: 1.0
|
||||
Archiver-Version: Plexus Archiver
|
||||
Created-By: Apache Maven 3.6.3
|
||||
Built-By: mitom
|
||||
Build-Jdk: 11
|
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Mon Jul 25 15:29:06 CST 2022
|
||||
groupId=cn.zyjblogs.starter
|
||||
artifactId=zyjblogs-web-spring-boot-starter
|
||||
version=1.0-SNAPSHOT
|
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>zyjblogs-parent</artifactId>
|
||||
<groupId>cn.zyjblogs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>zyjblogs-web-spring-boot-starter</artifactId>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- Spring 集成 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.zyjblogs.starter</groupId>
|
||||
<artifactId>zyjblogs-common-spring-boot-starter</artifactId>
|
||||
<version>${zyjblogs.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.zyjblogs.starter.web.config.Knife4jAutoConfigurationConfig
|
Loading…
Reference in New Issue
Block a user