升级Spring Boot到2.5.x,升级Spring Cloud到2020.x

This commit is contained in:
zlt2000
2021-08-08 22:13:11 +08:00
parent a652428079
commit e73511b72c
68 changed files with 350 additions and 1538 deletions
+4 -5
View File
@@ -1,9 +1,9 @@
# zlt-microservices-platform
<p align="center">
<img src="https://img.shields.io/badge/Spring%20Boot-2.3.12.RELEASE-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud-Hoxton.SR12-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud%20Alibaba-2.2.6.RELEASE-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Boot-2.5.3-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud-2020.0.3-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Spring%20Cloud%20Alibaba-2021.1-blue" alt="Downloads"/>
<img src="https://img.shields.io/badge/Elasticsearch-7.x-brightgreen" alt="Downloads"/>
<a target="_blank" href='https://gitee.com/zlt2000/microservices-platform'>
<img src='https://gitee.com/zlt2000/microservices-platform/badge/star.svg' alt='star'/>
@@ -75,7 +75,7 @@ central-platform -- 父项目,公共依赖
│ │ ├─zlt-db-spring-boot-starter -- 封装数据库通用操作逻辑
│ │ ├─zlt-log-spring-boot-starter -- 封装log通用操作逻辑
│ │ ├─zlt-redis-spring-boot-starter -- 封装Redis通用操作逻辑
│ │ ├─zlt-ribbon-spring-boot-starter -- 封装Ribbon和Feign的通用操作逻辑
│ │ ├─zlt-loadbalancer-spring-boot-starter -- 封装Loadbalancer和Feign的通用操作逻辑
│ │ ├─zlt-sentinel-spring-boot-starter -- 封装Sentinel的通用操作逻辑
│ │ ├─zlt-swagger2-spring-boot-starter -- 封装Swagger通用操作逻辑
│ │ ├─zlt-elasticsearch-spring-boot-starter -- 封装Elasticsearch通用操作逻辑
@@ -85,7 +85,6 @@ central-platform -- 父项目,公共依赖
│ ├─zlt-doc -- 项目文档
│ ├─zlt-gateway -- api网关一级工程
│ │ ├─sc-gateway -- spring-cloud-gateway[9900]
│ │ ├─zuul-gateway -- netflix-zuul[9900]
│ ├─zlt-job -- 分布式任务调度一级工程
│ │ ├─job-admin -- 任务管理器[8081]
│ │ ├─job-core -- 任务调度核心代码
+41 -6
View File
@@ -13,21 +13,21 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>8</java.version>
<spring-cloud-alibaba-dependencies.version>2.2.6.RELEASE</spring-cloud-alibaba-dependencies.version>
<spring-boot-dependencies.version>2.3.12.RELEASE</spring-boot-dependencies.version>
<spring-cloud-dependencies.version>Hoxton.SR12</spring-cloud-dependencies.version>
<spring-cloud-alibaba-dependencies.version>2021.1</spring-cloud-alibaba-dependencies.version>
<spring-boot-dependencies.version>2.5.3</spring-boot-dependencies.version>
<spring-cloud-dependencies.version>2020.0.3</spring-cloud-dependencies.version>
<commons-collections4.version>4.4</commons-collections4.version>
<swagger.version>2.9.2</swagger.version>
<swagger.ui.version>1.8.7</swagger.ui.version>
<swagger.mg.ui.version>1.0.6</swagger.mg.ui.version>
<swagger.butler.version>2.0.1</swagger.butler.version>
<jjwt.version>0.9.1</jjwt.version>
<druid-starter>1.1.22</druid-starter>
<druid-starter>1.2.6</druid-starter>
<jasypt.version>1.14</jasypt.version>
<sharding-sphere.version>3.1.0</sharding-sphere.version>
<security-oauth2.version>2.3.8.RELEASE</security-oauth2.version>
<security-jwt.version>1.1.0.RELEASE</security-jwt.version>
<redisson-starter.version>3.16.0</redisson-starter.version>
<redisson-starter.version>3.16.1</redisson-starter.version>
<easyCaptcha.version>1.6.2</easyCaptcha.version>
<hutool.version>5.1.4</hutool.version>
<mybatis-plus-boot-starter.version>3.4.0</mybatis-plus-boot-starter.version>
@@ -53,6 +53,11 @@
<hibernate-validator.version>6.2.0.Final</hibernate-validator.version>
<dubbo.version>2.7.8</dubbo.version>
<curator.version>5.1.0</curator.version>
<jackson-databind.version>2.12.4</jackson-databind.version>
<commons-configuration.version>1.10</commons-configuration.version>
<zuul.version>2.2.9.RELEASE</zuul.version>
<aws-java-sdk-s3.version>1.12.40</aws-java-sdk-s3.version>
<spring-cloud-starter-oauth2.version>2.2.5.RELEASE</spring-cloud-starter-oauth2.version>
<docker-maven-plugin.version>1.2.2</docker-maven-plugin.version>
<sonar.exclusions>zlt-job/**/*, zlt-register/**/*, zlt-web/**/*</sonar.exclusions>
<docker.baseImage>openjdk:8-jre-alpine</docker.baseImage>
@@ -87,6 +92,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
@@ -119,7 +129,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@@ -371,6 +381,31 @@
<artifactId>curator-framework</artifactId>
<version>${curator.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<version>${spring-cloud-starter-oauth2.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws-java-sdk-s3.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
<version>${zuul.version}</version>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>${commons-configuration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
+4
View File
@@ -59,6 +59,10 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
</dependencies>
<build>
+1 -1
View File
@@ -24,7 +24,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
@@ -1,6 +1,6 @@
package com.central;
import com.central.common.ribbon.annotation.EnableFeignInterceptor;
import com.central.common.lb.annotation.EnableFeignInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -13,7 +13,7 @@
<dependencies>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
@@ -2,7 +2,7 @@ package com.central.search.client.feign.fallback;
import cn.hutool.core.map.MapUtil;
import com.central.search.client.feign.AggregationService;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -3,7 +3,7 @@ package com.central.search.client.feign.fallback;
import com.central.common.model.PageResult;
import com.central.search.client.feign.SearchService;
import com.fasterxml.jackson.databind.JsonNode;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
/**
+6 -1
View File
@@ -28,7 +28,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
@@ -81,6 +81,11 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -1,6 +1,6 @@
package com.central;
import com.central.common.ribbon.annotation.EnableFeignInterceptor;
import com.central.common.lb.annotation.EnableFeignInterceptor;
import com.central.search.annotation.EnableSearchClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -5,11 +5,11 @@ import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.central.common.annotation.LoginUser;
import com.central.common.constant.CommonConstant;
import com.central.common.model.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
@@ -40,7 +40,7 @@ public class SysMenuController {
public static List<SysMenu> treeBuilder(List<SysMenu> sysMenus) {
List<SysMenu> menus = new ArrayList<>();
for (SysMenu sysMenu : sysMenus) {
if (ObjectUtils.equals(-1L, sysMenu.getParentId())) {
if (ObjectUtil.equal(-1L, sysMenu.getParentId())) {
menus.add(sysMenu);
}
for (SysMenu menu : sysMenus) {
+1 -1
View File
@@ -16,7 +16,7 @@
<module>zlt-db-spring-boot-starter</module>
<module>zlt-swagger2-spring-boot-starter</module>
<module>zlt-log-spring-boot-starter</module>
<module>zlt-ribbon-spring-boot-starter</module>
<module>zlt-loadbalancer-spring-boot-starter</module>
<module>zlt-auth-client-spring-boot-starter</module>
<module>zlt-sentinel-spring-boot-starter</module>
<module>zlt-common-core</module>
@@ -25,6 +25,9 @@ import java.util.stream.Collectors;
*
* @author zlt
* @date 2018/10/28
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Slf4j
public abstract class DefaultPermissionServiceImpl {
@@ -32,7 +35,7 @@ public abstract class DefaultPermissionServiceImpl {
@Autowired
private SecurityProperties securityProperties;
private AntPathMatcher antPathMatcher = new AntPathMatcher();
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
/**
* 查询当前用户拥有的资源权限
@@ -3,7 +3,7 @@ package com.central.common.feign.fallback;
import com.central.common.feign.UserService;
import com.central.common.model.LoginAppUser;
import com.central.common.model.SysUser;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
/**
@@ -1,48 +1,48 @@
<?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>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>4.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<description>远程通信通用组件</description>
<dependencies>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
<?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>
<groupId>com.zlt</groupId>
<artifactId>zlt-commons</artifactId>
<version>4.6.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
<description>负载均衡通用组件</description>
<dependencies>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
@@ -1,77 +1,80 @@
package com.central.common.ribbon;
import com.central.common.ribbon.config.RestTemplateProperties;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* @author zlt
* @date 2018/11/17
*/
@EnableConfigurationProperties(RestTemplateProperties.class)
public class RestTemplateAutoConfigure {
@Autowired
private RestTemplateProperties restTemplateProperties;
@LoadBalanced
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(httpRequestFactory());
return restTemplate;
}
/**
* httpclient 实现的ClientHttpRequestFactory
*/
@Bean
public ClientHttpRequestFactory httpRequestFactory() {
return new HttpComponentsClientHttpRequestFactory(httpClient());
}
/**
* 使用连接池的 httpclient
*/
@Bean
public HttpClient httpClient() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
// 最大链接数
connectionManager.setMaxTotal(restTemplateProperties.getMaxTotal());
// 同路由并发数20
connectionManager.setDefaultMaxPerRoute(restTemplateProperties.getMaxPerRoute());
RequestConfig requestConfig = RequestConfig.custom()
// 读超时
.setSocketTimeout(restTemplateProperties.getReadTimeout())
// 链接超时
.setConnectTimeout(restTemplateProperties.getConnectTimeout())
// 链接不够用的等待时间
.setConnectionRequestTimeout(restTemplateProperties.getReadTimeout())
.build();
return HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
}
}
package com.central.common.lb;
import com.central.common.lb.config.RestTemplateProperties;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
/**
* @author zlt
* @date 2018/11/17
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@EnableConfigurationProperties(RestTemplateProperties.class)
public class RestTemplateAutoConfigure {
@Autowired
private RestTemplateProperties restTemplateProperties;
@LoadBalanced
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory httpRequestFactory) {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(httpRequestFactory);
return restTemplate;
}
/**
* httpclient 实现的ClientHttpRequestFactory
*/
@Bean
public ClientHttpRequestFactory httpRequestFactory(HttpClient httpClient) {
return new HttpComponentsClientHttpRequestFactory(httpClient);
}
/**
* 使用连接池的 httpclient
*/
@Bean
public HttpClient httpClient() {
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
// 最大链接数
connectionManager.setMaxTotal(restTemplateProperties.getMaxTotal());
// 同路由并发数20
connectionManager.setDefaultMaxPerRoute(restTemplateProperties.getMaxPerRoute());
RequestConfig requestConfig = RequestConfig.custom()
// 读超时
.setSocketTimeout(restTemplateProperties.getReadTimeout())
// 链接超时
.setConnectTimeout(restTemplateProperties.getConnectTimeout())
// 链接不够用的等待时间
.setConnectionRequestTimeout(restTemplateProperties.getReadTimeout())
.build();
return HttpClientBuilder.create()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
}
}
@@ -1,6 +1,6 @@
package com.central.common.ribbon.annotation;
package com.central.common.lb.annotation;
import com.central.common.ribbon.config.FeignInterceptorConfig;
import com.central.common.lb.config.FeignInterceptorConfig;
import org.springframework.context.annotation.Import;
import java.lang.annotation.ElementType;
@@ -22,4 +22,4 @@ import java.lang.annotation.Target;
@Import(FeignInterceptorConfig.class)
public @interface EnableBaseFeignInterceptor {
}
}
@@ -1,7 +1,7 @@
package com.central.common.ribbon.annotation;
package com.central.common.lb.annotation;
import com.central.common.ribbon.config.FeignHttpInterceptorConfig;
import com.central.common.ribbon.config.FeignInterceptorConfig;
import com.central.common.lb.config.FeignHttpInterceptorConfig;
import com.central.common.lb.config.FeignInterceptorConfig;
import org.springframework.context.annotation.Import;
import java.lang.annotation.ElementType;
@@ -14,9 +14,11 @@ import java.lang.annotation.Target;
*
* @author zlt
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import({FeignInterceptorConfig.class, FeignHttpInterceptorConfig.class})
public @interface EnableFeignInterceptor {
}
@@ -1,4 +1,4 @@
package com.central.common.ribbon.config;
package com.central.common.lb.config;
import com.central.common.constant.CommonConstant;
import com.central.common.constant.SecurityConstants;
@@ -1,4 +1,4 @@
package com.central.common.ribbon.config;
package com.central.common.lb.config;
import cn.hutool.core.util.StrUtil;
import com.central.common.constant.SecurityConstants;
@@ -10,6 +10,9 @@ import org.springframework.context.annotation.Bean;
* feign拦截器,只包含基础数据
*
* @author zlt
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
public class FeignInterceptorConfig {
/**
@@ -1,33 +1,36 @@
package com.central.common.ribbon.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* RestTemplate 配置
*
* @author zlt
* @date 2017/11/17
*/
@Setter
@Getter
@ConfigurationProperties(prefix = "zlt.rest-template")
public class RestTemplateProperties {
/**
* 最大链接数
*/
private int maxTotal = 200;
/**
* 同路由最大并发数
*/
private int maxPerRoute = 50;
/**
* 读取超时时间 ms
*/
private int readTimeout = 35000;
/**
* 链接超时时间 ms
*/
private int connectTimeout = 10000;
}
package com.central.common.lb.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* RestTemplate 配置
*
* @author zlt
* @date 2017/11/17
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Setter
@Getter
@ConfigurationProperties(prefix = "zlt.rest-template")
public class RestTemplateProperties {
/**
* 最大链接数
*/
private int maxTotal = 200;
/**
* 同路由最大并发数
*/
private int maxPerRoute = 50;
/**
* 读取超时时间 ms
*/
private int readTimeout = 35000;
/**
* 链接超时时间 ms
*/
private int connectTimeout = 10000;
}
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.central.common.lb.RestTemplateAutoConfigure
@@ -1,21 +0,0 @@
package com.central.common.ribbon;
import feign.Logger;
import org.springframework.context.annotation.Bean;
/**
* Feign统一配置
*
* @author zlt
* @date 2018/9/18 14:04
*/
public class FeignAutoConfigure {
/**
* Feign 日志级别
*/
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
@@ -1,21 +0,0 @@
package com.central.common.ribbon;
import com.central.common.constant.ConfigConstants;
import com.central.common.ribbon.config.RuleConfigure;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
/**
* 自定义负载均衡配置
*
* @author zlt
* @date 2019/9/3
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@ConditionalOnProperty(value = ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED, havingValue = "true")
@RibbonClients(defaultConfiguration = {RuleConfigure.class})
public class LbIsolationAutoConfigure {
}
@@ -1,20 +0,0 @@
package com.central.common.ribbon;
import com.central.common.ribbon.config.RestTemplateProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.ribbon.DefaultPropertiesFactory;
import org.springframework.context.annotation.Bean;
/**
* Ribbon扩展配置类
*
* @author zlt
* @date 2018/11/17 9:24
*/
@EnableConfigurationProperties(RestTemplateProperties.class)
public class RibbonAutoConfigure {
@Bean
public DefaultPropertiesFactory defaultPropertiesFactory() {
return new DefaultPropertiesFactory();
}
}
@@ -1,24 +0,0 @@
package com.central.common.ribbon.config;
import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.central.common.ribbon.rule.VersionIsolationRule;
import com.netflix.loadbalancer.IRule;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
/**
* @author zlt
* @date 2020/4/24
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
public class RuleConfigure {
@Bean
@ConditionalOnClass(NacosServer.class)
@ConditionalOnMissingBean
public IRule versionIsolationRule() {
return new VersionIsolationRule();
}
}
@@ -1,50 +0,0 @@
package com.central.common.ribbon.filter;
import cn.hutool.core.util.StrUtil;
import com.central.common.constant.CommonConstant;
import com.central.common.constant.ConfigConstants;
import com.central.common.context.LbIsolationContextHolder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 负载均衡隔离规则过滤器
*
* @author zlt
* @date 2019/9/15
*/
@ConditionalOnClass(Filter.class)
public class LbIsolationFilter extends OncePerRequestFilter {
@Value("${" + ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED + ":false}")
private boolean enableIsolation;
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return !enableIsolation;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
try {
String version = request.getHeader(CommonConstant.Z_L_T_VERSION);
if(StrUtil.isNotEmpty(version)){
LbIsolationContextHolder.setVersion(version);
}
filterChain.doFilter(request, response);
} finally {
LbIsolationContextHolder.clear();
}
}
}
@@ -1,80 +0,0 @@
package com.central.common.ribbon.rule;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.central.common.constant.CommonConstant;
import com.central.common.context.LbIsolationContextHolder;
import com.netflix.loadbalancer.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* 根据实例版本号隔离规则
* 详细用法:https://mp.weixin.qq.com/s/9XQ-SIbYsov3KBx9TGFN0g
*
* 实例获取规则顺序如下(不满足则走下一个规则):
* 1. 相同版本号的实例
* 2. 无版本号的实例
* 3. 所有实例中轮询
*
* @author zlt
* @date 2019/9/3
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
public class VersionIsolationRule extends RoundRobinRule {
private final static String KEY_DEFAULT = "default";
/**
* 优先根据版本号取实例
*/
@Override
public Server choose(ILoadBalancer lb, Object key) {
if (lb == null) {
return null;
}
String version;
if (key != null && !KEY_DEFAULT.equals(key)) {
version = key.toString();
} else {
version = LbIsolationContextHolder.getVersion();
}
List<Server> targetList = null;
List<Server> upList = lb.getReachableServers();
if (StrUtil.isNotEmpty(version)) {
//取指定版本号的实例
targetList = upList.stream().filter(
server -> version.equals(
((NacosServer) server).getMetadata().get(CommonConstant.METADATA_VERSION)
)
).collect(Collectors.toList());
}
if (CollUtil.isEmpty(targetList)) {
//只取无版本号的实例
targetList = upList.stream().filter(
server -> {
String metadataVersion = ((NacosServer) server).getMetadata().get(CommonConstant.METADATA_VERSION);
return StrUtil.isEmpty(metadataVersion);
}
).collect(Collectors.toList());
}
if (CollUtil.isNotEmpty(targetList)) {
return getServer(targetList);
}
return super.choose(lb, key);
}
/**
* 随机取一个实例
*/
private Server getServer(List<Server> upList) {
int nextInt = RandomUtil.randomInt(upList.size());
return upList.get(nextInt);
}
}
@@ -1,50 +0,0 @@
package org.springframework.cloud.netflix.ribbon;
import com.netflix.loadbalancer.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
import static org.springframework.cloud.netflix.ribbon.SpringClientFactory.NAMESPACE;
/**
* 扩展 spring cloud ribbon的PropertiesFactory
* 使其能够支持 配置全局的ribbon.NFLoadBalancerRuleClassName=package.YourRule
* 然后各个微服务还可以根据自身情况做个性化定制。如:SERVICE_ID.ribbon.NFLoadBalancerRuleClassName=package.YourRule
*
* @author zlt
* @date 2018/11/17 9:29
*/
public class DefaultPropertiesFactory extends PropertiesFactory {
@Autowired
private Environment environment;
private Map<Class, String> classToProperty = new HashMap<>(5);
public DefaultPropertiesFactory() {
super();
classToProperty.put(ILoadBalancer.class, "NFLoadBalancerClassName");
classToProperty.put(IPing.class, "NFLoadBalancerPingClassName");
classToProperty.put(IRule.class, "NFLoadBalancerRuleClassName");
classToProperty.put(ServerList.class, "NIWSServerListClassName");
classToProperty.put(ServerListFilter.class, "NIWSServerListFilterClassName");
}
/**
* 重写 支持 ribbon.NFLoadBalancerRuleClassName=package.YourRule 全局配置的方式
*/
@Override
public String getClassName(Class clazz, String name) {
String className = super.getClassName(clazz, name);
// 读取全局配置
if(!StringUtils.hasText(className) && this.classToProperty.containsKey(clazz)){
String classNameProperty = this.classToProperty.get(clazz);
className = environment.getProperty(NAMESPACE + "." + classNameProperty);
}
return className;
}
}
@@ -1,6 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.central.common.ribbon.RibbonAutoConfigure,\
com.central.common.ribbon.FeignAutoConfigure,\
com.central.common.ribbon.RestTemplateAutoConfigure,\
com.central.common.ribbon.filter.LbIsolationFilter,\
com.central.common.ribbon.LbIsolationAutoConfigure
@@ -1,18 +1,7 @@
########################## application级别通用配置 ##########################
##### ribbon配置
## 从注册中心刷新servelist的时间 默认30秒,单位ms
ribbon.ServerListRefreshInterval=15000
## 请求连接的超时时间 默认1秒,单位ms
ribbon.ConnectTimeout=30000
## 请求处理的超时时间 默认1秒,单位ms
ribbon.ReadTimeout=30000
## 对所有操作请求都进行重试,不配置这个MaxAutoRetries不起作用 默认false
#ribbon.OkToRetryOnAllOperations=true
## 对当前实例的重试次数 默认0
#ribbon.MaxAutoRetries=1
## 切换实例的重试次数 默认1
ribbon.MaxAutoRetriesNextServer=0
##### loadbalancer配置
## 切换实例的重试
spring.cloud.loadbalancer.retry.enabled=false
##### feign配置
feign.sentinel.enabled=true
+1 -1
View File
@@ -12,7 +12,7 @@
<dependencies>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
+1 -1
View File
@@ -17,7 +17,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
+1 -1
View File
@@ -17,7 +17,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -40,7 +40,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
-2
View File
@@ -9,8 +9,6 @@
<artifactId>zlt-gateway</artifactId>
<packaging>pom</packaging>
<modules>
<!-- zuul -->
<module>zuul-gateway</module>
<!-- spring cloud gateway -->
<module>sc-gateway</module>
</modules>
+5 -1
View File
@@ -16,7 +16,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
@@ -89,6 +89,10 @@
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
</dependencies>
<build>
@@ -1,6 +1,6 @@
package com.central;
import com.central.common.ribbon.annotation.EnableBaseFeignInterceptor;
import com.central.common.lb.annotation.EnableBaseFeignInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -1,7 +1,7 @@
package com.central.gateway.auth;
import com.central.common.model.SysMenu;
import com.central.gateway.feign.MenuService;
import com.central.gateway.feign.AsynMenuService;
import com.central.oauth2.common.service.impl.DefaultPermissionServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -14,7 +14,9 @@ import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Future;
/**
* url权限认证
@@ -29,7 +31,7 @@ import java.util.List;
@Component
public class PermissionAuthManager extends DefaultPermissionServiceImpl implements ReactiveAuthorizationManager<AuthorizationContext> {
@Resource
private MenuService menuService;
private AsynMenuService asynMenuService;
@Override
public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, AuthorizationContext authorizationContext) {
@@ -43,6 +45,12 @@ public class PermissionAuthManager extends DefaultPermissionServiceImpl implemen
@Override
public List<SysMenu> findMenuByRoleCodes(String roleCodes) {
return menuService.findByRoleCodes(roleCodes);
Future<List<SysMenu>> futureResult = asynMenuService.findByRoleCodes(roleCodes);
try {
return futureResult.get();
} catch (Exception e) {
log.error("asynMenuService.findMenuByRoleCodes-error", e);
}
return Collections.emptyList();
}
}
}
@@ -1,14 +1,19 @@
package com.central.gateway.config;
import com.central.common.config.DefaultAsycTaskConfig;
import org.springframework.context.annotation.Configuration;
/**
* @author zlt
* 线程池配置、启用异步
* @Async quartz 需要使用
*/
@Configuration
public class AsycTaskExecutorConfig extends DefaultAsycTaskConfig {
}
package com.central.gateway.config;
import com.central.common.config.DefaultAsycTaskConfig;
import org.springframework.context.annotation.Configuration;
/**
* 线程池配置、启用异步
*
* @author zlt
* @version 1.0
* @date 2021/8/8
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Configuration
public class AsycTaskExecutorConfig extends DefaultAsycTaskConfig {
}
@@ -29,7 +29,7 @@ public class CorsConfig {
// cookie跨域
config.setAllowCredentials(Boolean.TRUE);
config.addAllowedMethod(ALL);
config.addAllowedOrigin(ALL);
config.addAllowedOriginPattern(ALL);
config.addAllowedHeader(ALL);
// 配置前端js允许访问的自定义响应头
config.addExposedHeader("setToken");
@@ -0,0 +1,35 @@
package com.central.gateway.feign;
import com.central.common.model.SysMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.Future;
/**
* 异步Menu服务
*
* @author zlt
* @version 1.0
* @date 2021/8/8
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Component
public class AsynMenuService {
@Lazy
@Resource
private MenuService menuService;
@Async
public Future<List<SysMenu>> findByRoleCodes(String roleCodes) {
List<SysMenu> result = menuService.findByRoleCodes(roleCodes);
return new AsyncResult<>(result);
}
}
@@ -2,7 +2,7 @@ package com.central.gateway.feign.fallback;
import cn.hutool.core.collection.CollectionUtil;
import com.central.gateway.feign.MenuService;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -6,9 +6,9 @@ import com.central.common.constant.ConfigConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.config.LoadBalancerProperties;
/*import org.springframework.cloud.gateway.config.LoadBalancerProperties;
import org.springframework.cloud.gateway.filter.LoadBalancerClientFilter;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;*/
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@@ -25,6 +25,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.G
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
/*
@Component
@ConditionalOnProperty(name = ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED, havingValue = "true")
public class LbIsolationFilter extends LoadBalancerClientFilter {
@@ -45,3 +46,4 @@ public class LbIsolationFilter extends LoadBalancerClientFilter {
return super.choose(exchange);
}
}
*/
-13
View File
@@ -1,13 +0,0 @@
FROM openjdk:8u292
LABEL MAINTAINER=Andy
WORKDIR /apps
ADD target/zuul-gateway.jar /apps/
CMD ["java","-jar","zuul-gateway.jar"]
# docker run --name zuul-gateway \
# -e spring_cloud_nacos_server_addr=10.0.0.12:8848 \
# -e zlt_datasource_ip=10.0.0.12 \
# -e zlt_datasource_username=root \
# -e zlt_datasource_password=redhat \
# -e spring_redis_host=10.0.0.12 \
# -d zuul-gateway:4.5
-150
View File
@@ -1,150 +0,0 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zlt</groupId>
<artifactId>zlt-gateway</artifactId>
<version>4.6.0</version>
</parent>
<artifactId>zuul-gateway</artifactId>
<description>zuul网关</description>
<dependencies>
<!-- 公共实体类模块 -->
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-config</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-sentinel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-redis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除tomcat容器-->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 替换undertow容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- swagger -->
<dependency>
<groupId>com.github.zlt2000</groupId>
<artifactId>swagger-butler-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>eu.bitwalker</groupId>
<artifactId>UserAgentUtils</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<imageTags>
<imageTag>${project.version}</imageTag>
<imageTag>latest</imageTag>
</imageTags>
<forceTags>true</forceTags>
<baseImage>${docker.baseImage}</baseImage>
<volumes>${docker.volumes}</volumes>
<env>
<JAVA_OPTS>${docker.java.opts}</JAVA_OPTS>
</env>
<entryPoint>["sh","-c","java $JAVA_OPTS ${docker.java.security.egd} -jar /${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
@@ -1,23 +0,0 @@
package com.central;
import com.central.common.ribbon.annotation.EnableBaseFeignInterceptor;
import com.central.common.ribbon.annotation.EnableFeignInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author zlt
*/
@EnableZuulProxy
@EnableFeignClients
@EnableBaseFeignInterceptor
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApp {
public static void main(String[] args) {
SpringApplication.run(GatewayApp.class, args);
}
}
@@ -1,48 +0,0 @@
package com.central.gateway.config;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* 跨域配置
*
* @author zlt
* @date 2018/8/9 15:59
*/
@Configuration
public class CorsConfigration {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// #允许向该服务器提交请求的URI,*表示全部允许
config.addAllowedOrigin(CorsConfiguration.ALL);
// 允许cookies跨域
config.setAllowCredentials(true);
// #允许访问的头信息,*表示全部
config.addAllowedHeader(CorsConfiguration.ALL);
// 允许提交请求的方法,*表示全部允许
config.addAllowedMethod(CorsConfiguration.ALL);
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
/**
* 配置过滤器
*/
@Bean
public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean<CorsFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(corsFilter());
registration.addUrlPatterns("/*");
registration.setName("corsFilter");
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
return registration;
}
}
@@ -1,45 +0,0 @@
package com.central.gateway.config;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.central.gateway.route.nacos.NacosDynRouteLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 动态路由配置
*
* @author zlt
* @date 2019/8/21
*/
@Configuration
@ConditionalOnProperty(prefix = "zlt.gateway.dynamicRoute", name = "enabled", havingValue = "true")
public class DynamicZuulRouteConfig {
@Autowired
private ZuulProperties zuulProperties;
@Autowired
private DispatcherServletPath dispatcherServletPath;
/**
* Nacos实现方式
*/
@Configuration
@ConditionalOnProperty(prefix = "zlt.gateway.dynamicRoute", name = "dataType", havingValue = "nacos", matchIfMissing = true)
public class NacosZuulRoute {
@Autowired
private NacosConfigProperties nacosConfigProperties;
@Autowired
private ApplicationEventPublisher publisher;
@Bean
public NacosDynRouteLocator nacosDynRouteLocator() {
return new NacosDynRouteLocator(nacosConfigProperties, publisher, dispatcherServletPath.getPrefix(), zuulProperties);
}
}
}
@@ -1,22 +0,0 @@
package com.central.gateway.config;
import com.central.common.config.DefaultPasswordConfig;
import com.central.oauth2.common.config.DefaultResourceServerConf;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
/**
* @author zlt
*/
@Configuration
@EnableResourceServer
@Import({DefaultPasswordConfig.class})
public class ResourceServerConfiguration extends DefaultResourceServerConf {
@Override
public HttpSecurity setAuthenticate(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.AuthorizedUrl authorizedUrl) {
return authorizedUrl.access("@permissionService.hasPermission(request, authentication)").and();
}
}
@@ -1,16 +0,0 @@
package com.central.gateway.config;
import com.didispace.swagger.butler.EnableSwaggerButler;
import org.springframework.context.annotation.Configuration;
/**
* swagger 聚合文档配置
* zuul routers 映射具体服务的/v2/api-docs swagger
*
* @author 作者 owen E-mail: 624191343@qq.com
*/
@Configuration
@EnableSwaggerButler
public class SwaggerConfig {
}
@@ -1,49 +0,0 @@
package com.central.gateway.config;
import lombok.Getter;
import lombok.Setter;
/**
* zuul路由实体
*
* @author zlt
* @date 2019/8/21
*/
@Setter
@Getter
public class ZuulRouteEntity {
/**
* The ID of the route (the same as its map key by default).
*/
private String id;
/**
* The path (pattern) for the route, e.g. /foo/**.
*/
private String path;
/**
* The service ID (if any) to map to this route. You can specify a
* physical URL or a service, but not both.
*/
private String serviceId;
/**
* A full physical URL to map to the route. An alternative is to use a
* service ID and service discovery to find the physical address.
*/
private String url;
/**
* Flag to determine whether the prefix for this route (the path, minus
* pattern patcher) should be stripped before forwarding.
*/
private boolean stripPrefix = true;
/**
* Flag to indicate that this route should be retryable (if supported).
* Generally retry requires a service ID and ribbon.
*/
private Boolean retryable;
private String apiName;
private boolean enabled = true;
private boolean customSensitiveHeaders = true;
}
@@ -1,23 +0,0 @@
package com.central.gateway.feign;
import com.central.common.constant.ServiceNameConstants;
import com.central.common.model.SysMenu;
import com.central.gateway.feign.fallback.MenuServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.List;
/**
* @author zlt
*/
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = MenuServiceFallbackFactory.class, decode404 = true)
public interface MenuService {
/**
* 角色菜单列表
* @param roleCodes
*/
@GetMapping(value = "/menus/{roleCodes}")
List<SysMenu> findByRoleCodes(@PathVariable("roleCodes") String roleCodes);
}
@@ -1,25 +0,0 @@
package com.central.gateway.feign.fallback;
import cn.hutool.core.collection.CollectionUtil;
import com.central.gateway.feign.MenuService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* menuService降级工场
*
* @author zlt
* @date 2019/1/18
*/
@Slf4j
@Component
public class MenuServiceFallbackFactory implements FallbackFactory<MenuService> {
@Override
public MenuService create(Throwable throwable) {
return roleIds -> {
log.error("调用findByRoleCodes异常:{}", roleIds, throwable);
return CollectionUtil.newArrayList();
};
}
}
@@ -1,79 +0,0 @@
package com.central.gateway.filter.pre;
import cn.hutool.core.util.StrUtil;
import com.central.common.utils.AddrUtil;
import com.central.log.monitor.PointUtil;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import eu.bitwalker.useragentutils.UserAgent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
/**
* 请求统计分析埋点过滤器
*
* @author zlt
* @date 2019/5/6
*/
@Slf4j
@Component
public class RequestStatisticsFilter extends ZuulFilter {
@Override
public String filterType() {
return FilterConstants.PRE_TYPE;
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest req = ctx.getRequest();
UserAgent userAgent = UserAgent.parseUserAgentString(req.getHeader("User-Agent"));
//埋点
PointUtil.debug("0", "request-statistics",
"ip=" + AddrUtil.getRemoteAddr(req)
+ "&browser=" + getBrowser(userAgent.getBrowser().getName())
+ "&operatingSystem=" + getOperatingSystem(userAgent.getOperatingSystem().getName()));
return null;
}
private String getBrowser(String browser) {
if (StrUtil.isNotEmpty(browser)) {
if (browser.contains("CHROME")) {
return "CHROME";
} else if (browser.contains("FIREFOX")) {
return "FIREFOX";
} else if (browser.contains("SAFARI")) {
return "SAFARI";
} else if (browser.contains("EDGE")) {
return "EDGE";
}
}
return browser;
}
private String getOperatingSystem(String operatingSystem) {
if (StrUtil.isNotEmpty(operatingSystem)) {
if (operatingSystem.contains("MAC_OS_X")) {
return "MAC_OS_X";
} else if (operatingSystem.contains("ANDROID")) {
return "ANDROID";
}
}
return operatingSystem;
}
}
@@ -1,51 +0,0 @@
package com.central.gateway.filter.pre;
import cn.hutool.core.util.IdUtil;
import com.central.common.constant.CommonConstant;
import com.central.log.properties.TraceProperties;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER;
/**
* 生成日志链路追踪id,并传入header中
*
* @author zlt
* @date 2019/8/13
*/
@Component
public class TraceFilter extends ZuulFilter {
@Autowired
private TraceProperties traceProperties;
@Override
public String filterType() {
return FilterConstants.PRE_TYPE;
}
@Override
public int filterOrder() {
return FORM_BODY_WRAPPER_FILTER_ORDER - 1;
}
@Override
public boolean shouldFilter() {
//根据配置控制是否开启过滤器
return traceProperties.getEnable();
}
@Override
public Object run() {
//链路追踪id
String traceId = IdUtil.fastSimpleUUID();
MDC.put(CommonConstant.LOG_TRACE_ID, traceId);
RequestContext ctx = RequestContext.getCurrentContext();
ctx.addZuulRequestHeader(CommonConstant.TRACE_ID_HEADER, traceId);
return null;
}
}
@@ -1,65 +0,0 @@
package com.central.gateway.filter.pre;
import cn.hutool.core.collection.CollectionUtil;
import com.central.common.constant.SecurityConstants;
import com.central.common.model.SysUser;
import com.central.oauth2.common.util.AuthUtils;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.stereotype.Component;
import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER;
/**
* 将认证用户的相关信息放入header中, 后端服务可以直接读取使用
*
* @author zlt
* @date 2018/11/20
* <p>
* Blog: https://zlt2000.gitee.io
* Github: https://github.com/zlt2000
*/
@Component
public class UserInfoHeaderFilter extends ZuulFilter {
@Override
public String filterType() {
return FilterConstants.PRE_TYPE;
}
@Override
public int filterOrder() {
return FORM_BODY_WRAPPER_FILTER_ORDER - 1;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public Object run() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) {
Object principal = authentication.getPrincipal();
RequestContext ctx = RequestContext.getCurrentContext();
//客户端模式只返回一个clientId
if (principal instanceof SysUser) {
SysUser user = (SysUser)principal;
ctx.addZuulRequestHeader(SecurityConstants.USER_ID_HEADER, String.valueOf(user.getId()));
ctx.addZuulRequestHeader(SecurityConstants.USER_HEADER, user.getUsername());
}
OAuth2Authentication oauth2Authentication = (OAuth2Authentication)authentication;
String clientId = oauth2Authentication.getOAuth2Request().getClientId();
ctx.addZuulRequestHeader(SecurityConstants.TENANT_HEADER, clientId);
ctx.addZuulRequestHeader(SecurityConstants.ROLE_HEADER, CollectionUtil.join(authentication.getAuthorities(), ","));
String accountType = AuthUtils.getAccountType(oauth2Authentication.getUserAuthentication());
ctx.addZuulRequestHeader(SecurityConstants.ACCOUNT_TYPE_HEADER, accountType);
}
return null;
}
}
@@ -1,64 +0,0 @@
package com.central.gateway.route;
import org.springframework.cloud.netflix.zuul.filters.RefreshableRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.SimpleRouteLocator;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.util.StringUtils;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 扩展 {@link SimpleRouteLocator} 实现动态路由
*
* @author zlt
* @date 2019/8/21
*/
public abstract class AbstractDynRouteLocator extends SimpleRouteLocator implements RefreshableRouteLocator {
private ZuulProperties properties;
public AbstractDynRouteLocator(String servletPath, ZuulProperties properties) {
super(servletPath, properties);
this.properties = properties;
}
/**
* 刷新路由
*/
@Override
public void refresh() {
doRefresh();
}
@Override
protected Map<String, ZuulRoute> locateRoutes() {
LinkedHashMap<String, ZuulRoute> routesMap = new LinkedHashMap<>();
// 从application.properties中加载静态路由信息
routesMap.putAll(super.locateRoutes());
// 从数据源中加载动态路由信息
routesMap.putAll(loadDynamicRoute());
// 优化一下配置
LinkedHashMap<String, ZuulRoute> values = new LinkedHashMap<>();
for (Map.Entry<String, ZuulRoute> entry : routesMap.entrySet()) {
String path = entry.getKey();
// Prepend with slash if not already present.
if (!path.startsWith("/")) {
path = "/" + path;
}
if (StringUtils.hasText(this.properties.getPrefix())) {
path = this.properties.getPrefix() + path;
if (!path.startsWith("/")) {
path = "/" + path;
}
}
values.put(path, entry.getValue());
}
return values;
}
/**
* 加载路由配置,由子类去实现
*/
public abstract Map<String, ZuulRoute> loadDynamicRoute();
}
@@ -1,113 +0,0 @@
package com.central.gateway.route.nacos;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import com.central.common.utils.JsonUtil;
import com.central.gateway.config.ZuulRouteEntity;
import com.central.gateway.route.AbstractDynRouteLocator;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.RoutesRefreshedEvent;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties.ZuulRoute;
import org.springframework.context.ApplicationEventPublisher;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* Nacos动态路由实现类
*
* @author zlt
* @date 2019/8/22
*/
@Slf4j
public class NacosDynRouteLocator extends AbstractDynRouteLocator {
private static final String ZUUL_DATA_ID = "zuul-routes";
private static final String ZUUL_GROUP_ID = "ZUUL_GATEWAY";
private NacosConfigProperties nacosConfigProperties;
private ApplicationEventPublisher publisher;
private NacosDynRouteLocator locator;
@Setter
private List<ZuulRouteEntity> zuulRouteEntities;
public NacosDynRouteLocator(NacosConfigProperties nacosConfigProperties, ApplicationEventPublisher publisher,
String servletPath, ZuulProperties properties) {
super(servletPath, properties);
this.nacosConfigProperties = nacosConfigProperties;
this.publisher = publisher;
this.locator = this;
addListener();
}
/**
* 添加Nacos监听
*/
private void addListener() {
try {
nacosConfigProperties.configServiceInstance().addListener(ZUUL_DATA_ID, ZUUL_GROUP_ID, new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
//赋值路由信息
locator.setZuulRouteEntities(getListByStr(configInfo));
RoutesRefreshedEvent routesRefreshedEvent = new RoutesRefreshedEvent(locator);
publisher.publishEvent(routesRefreshedEvent);
}
});
} catch (NacosException e) {
log.error("nacos-addListener-error", e);
}
}
@Override
public Map<String, ZuulProperties.ZuulRoute> loadDynamicRoute() {
Map<String, ZuulRoute> routes = new LinkedHashMap<>();
if (zuulRouteEntities == null) {
zuulRouteEntities = getNacosConfig();
}
for (ZuulRouteEntity result : zuulRouteEntities) {
if (StrUtil.isBlank(result.getPath()) || !result.isEnabled()) {
continue;
}
ZuulRoute zuulRoute = new ZuulRoute();
BeanUtil.copyProperties(result, zuulRoute);
routes.put(zuulRoute.getPath(), zuulRoute);
}
return routes;
}
/**
* 查询zuul的路由配置
*/
private List<ZuulRouteEntity> getNacosConfig() {
try {
String content = nacosConfigProperties.configServiceInstance().getConfig(ZUUL_DATA_ID, ZUUL_GROUP_ID,5000);
return getListByStr(content);
} catch (NacosException e) {
log.error("listenerNacos-error", e);
}
return new ArrayList<>(0);
}
public List<ZuulRouteEntity> getListByStr(String content) {
if (StrUtil.isNotEmpty(content)) {
return JsonUtil.toList(content, ZuulRouteEntity.class);
}
return new ArrayList<>(0);
}
}
@@ -1,33 +0,0 @@
package com.central.gateway.service.impl;
import com.central.common.model.SysMenu;
import com.central.gateway.feign.MenuService;
import com.central.oauth2.common.service.impl.DefaultPermissionServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* 请求权限判断service
*
* @author zlt
* @date 2018/10/28
*/
@Slf4j
@Service("permissionService")
public class PermissionServiceImpl extends DefaultPermissionServiceImpl {
@Resource
private MenuService menuService;
@Override
public List<SysMenu> findMenuByRoleCodes(String roleCodes) {
return menuService.findByRoleCodes(roleCodes);
}
public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
return hasPermission(authentication, request.getMethod(), request.getRequestURI());
}
}
@@ -1,16 +0,0 @@
{
"properties": [
{
"name": "zlt.gateway.dynamicRoute.enabled",
"description": "是否开启动态路由.",
"type": "java.lang.Boolean",
"defaultValue": false
},
{
"name": "zlt.gateway.dynamicRoute.dataType",
"description": "动态路由的数据类型.",
"type": "java.lang.String",
"defaultValue": "nacos"
}
]
}
@@ -1,169 +0,0 @@
#spring:
# sentinel动态配置规则
# cloud:
# sentinel:
# zuul:
# enabled: true
# order:
# pre: 2000
# post: 500
# error: -100
# filter:
# enabled: false
# datasource:
# 限流
# ds1:
# nacos:
# server-addr: ${spring.cloud.nacos.server-addr}
# dataId: ${spring.application.name}-sentinel-gw-flow
# groupId: DEFAULT_GROUP
# rule-type: gw-flow
# api分组
# ds2:
# nacos:
# server-addr: ${spring.cloud.nacos.server-addr}
# dataId: ${spring.application.name}-sentinel-gw-api-group
# groupId: DEFAULT_GROUP
# rule-type: gw-api-group
zlt:
oauth2:
token:
store:
type: redis
security:
ignore:
# 忽略认证的地址
httpUrls: >
/api-uaa/oauth/**,
/api-uaa/validata/**,
/api-uaa/css/**,
/api-uaa/images/**,
/api-uaa/js/**,
/api-user/users-anon/**,
/login.html,
/user/login
auth:
urlPermission:
#是否开启url级别权限
enable: false
#配置只进行登录认证,不进行url权限认证的api
ignoreUrls: >
/api-user/menus/current,
/api-user/users/current,
/api-log/requestStat
#白名单
includeClientIds:
- webApp
renew:
#是否开启token自动续签(目前只有redis实现)
enable: true
#白名单
includeClientIds:
- webApp
gateway:
#网关动态路由
dynamicRoute:
enabled: true
zuul:
ribbon-isolation-strategy: thread
ribbon:
eager-load:
enabled: true
threadPool:
useSeparateThreadPools: true
threadPoolKeyPrefix: api-gateway
#关闭重试
retryable: false
ignored-headers: Access-Control-Allow-Credentials,Access-Control-Allow-Origin,Access-Control-Allow-Methods
add-host-header: true
routes:
auth:
path: /api-uaa/**
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
auth-login-page:
path: /login.html
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
auth-login-process:
path: /user/login
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
auth-login-token:
path: /oauth/token
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
auth-login-authorize:
path: /oauth/authorize
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
auth-check-process:
path: /oauth/check_token
service-id: uaa-server
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
user:
path: /api-user/**
service-id: user-center
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
file:
path: /api-file/**
service-id: file-center
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
log:
path: /api-log/**
service-id: log-center
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
generator:
path: /api-generator/**
service-id: code-generator
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
search:
path: /api-search/**
service-id: search-center
strip-prefix: true
sensitive-headers: '*'
custom-sensitive-headers: true
ssl-hostname-validation-enabled: false
hystrix:
threadpool:
default:
coreSize: 100
maximumSize: 2000
allowMaximumSizeToDivergeFromCoreSize: true
maxQueueSize: -1
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 60000
swagger:
butler:
auto-generate-from-zuul-routes: true
generate-routes: user,file
apiDocsPath: v2/api-docs
@@ -1,9 +0,0 @@
server:
port: 9900
undertow:
buffer-size: 1024
direct-buffers: true
spring:
application:
name: api-gateway
@@ -1,9 +0,0 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjmgfejBXsPYynAIPczHA
eEvTDfAVaNKQudyI7VszdezbHDM1CStCIgwiMmLd7QYf1SrrmQoqxhcSRbhjE3ej
RF5qzhtx3kmepdpMrQptcsLjRkixaxCc4E2k6Us5707gGwbhoaTrRit5F2MnAdLY
C1TS3WwnO/hQfqUcAglbK8yrJ4AwAv0DAoIUSWnWqzuniV1SYbdV57uswxUssoWy
sEfPz+nv1ZLRs6Wz4eQ5Myqx2+CjWc9F8iXa2PV8Rmjms3dVbWcLUpCP18Dfzp8l
n8vF9LfYB7UaLSpfJe6FFF6+vCg4JHfo12djTUgwGjauMF3e9mmjU83KIoQS66lp
AQIDAQAB
-----END PUBLIC KEY-----
+1 -1
View File
@@ -19,7 +19,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<!-- swagger -->
<dependency>
+7 -2
View File
@@ -27,7 +27,7 @@
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-ribbon-spring-boot-starter</artifactId>
<artifactId>zlt-loadbalancer-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
@@ -93,7 +93,12 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
@@ -1,11 +1,10 @@
package com.central;
import com.central.common.ribbon.annotation.EnableFeignInterceptor;
import com.central.common.lb.annotation.EnableFeignInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
/**
* @author zlt
@@ -13,10 +12,12 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR
@EnableFeignClients
@EnableFeignInterceptor
@EnableDiscoveryClient
@EnableRedisHttpSession
//@EnableRedisHttpSession
@SpringBootApplication
public class UaaServerApp {
public static void main(String[] args) {
SpringApplication.run(UaaServerApp.class, args);
SpringApplication application = new SpringApplication(UaaServerApp.class);
application.setEnvironmentPrefix("zlt-uaa");
application.run(args);
}
}
@@ -1,6 +1,7 @@
package com.central.oauth.service.impl;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.central.common.feign.UserService;
import com.central.common.redis.template.RedisRepository;
import com.central.common.constant.SecurityConstants;
@@ -9,7 +10,6 @@ import com.central.common.model.SysUser;
import com.central.oauth.exception.ValidateCodeException;
import com.central.oauth.service.IValidateCodeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -96,11 +96,11 @@ public class ValidateCodeServiceImpl implements IValidateCodeService {
*/
@Override
public void validate(String deviceId, String validCode) {
if (StringUtils.isBlank(deviceId)) {
if (StrUtil.isBlank(deviceId)) {
throw new ValidateCodeException("请在请求参数中携带deviceId参数");
}
String code = this.getCode(deviceId);
if (StringUtils.isBlank(validCode)) {
if (StrUtil.isBlank(validCode)) {
throw new ValidateCodeException("请填写验证码");
}
@@ -108,7 +108,7 @@ public class ValidateCodeServiceImpl implements IValidateCodeService {
throw new ValidateCodeException("验证码不存在或已过期");
}
if (!StringUtils.equals(code, validCode.toLowerCase())) {
if (!StrUtil.equals(code, validCode.toLowerCase())) {
throw new ValidateCodeException("验证码不正确");
}