From 2f3949d732872ee9281cb6f1bc15dc3968bf418f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 27 May 2021 09:46:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7Spring=20Cloud=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=BB=84=E4=BB=B6=E5=88=B0=E6=9C=80=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 18 +++++++++------- .../api/factory/RemoteFileFallbackFactory.java | 2 +- .../api/factory/RemoteLogFallbackFactory.java | 2 +- .../api/factory/RemoteUserFallbackFactory.java | 2 +- ruoyi-common/ruoyi-common-core/pom.xml | 22 ++++++++++++-------- .../com/ruoyi/common/core/utils/StringUtils.java | 24 ++++++++++++++++++++++ .../common/security/aspect/PreAuthorizeAspect.java | 20 +++++++++--------- .../com/ruoyi/gateway/config/GatewayConfig.java | 9 -------- .../java/com/ruoyi/gen/RuoYiGenApplication.java | 4 ++-- .../java/com/ruoyi/job/RuoYiJobApplication.java | 4 ++-- .../com/ruoyi/system/RuoYiSystemApplication.java | 4 ++-- .../modules/monitor/RuoYiMonitorApplication.java | 6 +++--- 12 files changed, 71 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index 416ab32..a3ce520 100644 --- a/pom.xml +++ b/pom.xml @@ -17,10 +17,10 @@ UTF-8 UTF-8 1.8 - 2.3.7.RELEASE - Hoxton.SR9 - 2.2.5.RELEASE - 2.3.1 + 2.5.0 + 2020.0.2 + 2021.1 + 2.4.1 2.1.4 2.9.2 1.5.24 @@ -28,12 +28,12 @@ 2.3.2 1.3.0 1.2.6 - 3.2.1 + 3.3.2 2.5 1.3.3 1.7 1.2.76 - 8.0.3 + 8.2.1 4.1.2 2.6.2 @@ -234,7 +234,11 @@ pom - + + + org.springframework.cloud + spring-cloud-starter-bootstrap + diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java index 0654256..bc3b6ff 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java @@ -2,12 +2,12 @@ package com.ruoyi.system.api.factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.core.domain.R; import com.ruoyi.system.api.RemoteFileService; import com.ruoyi.system.api.domain.SysFile; -import feign.hystrix.FallbackFactory; /** * 文件服务降级处理 diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java index 8d1d9cd..0be325d 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteLogFallbackFactory.java @@ -2,11 +2,11 @@ package com.ruoyi.system.api.factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; import com.ruoyi.common.core.domain.R; import com.ruoyi.system.api.RemoteLogService; import com.ruoyi.system.api.domain.SysOperLog; -import feign.hystrix.FallbackFactory; /** * 日志服务降级处理 diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java index 6254ac7..45900b4 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteUserFallbackFactory.java @@ -2,11 +2,11 @@ package com.ruoyi.system.api.factory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; import com.ruoyi.common.core.domain.R; import com.ruoyi.system.api.RemoteUserService; import com.ruoyi.system.api.model.LoginUser; -import feign.hystrix.FallbackFactory; /** * 用户服务降级处理 diff --git a/ruoyi-common/ruoyi-common-core/pom.xml b/ruoyi-common/ruoyi-common-core/pom.xml index 5c437f0..ff8ed86 100644 --- a/ruoyi-common/ruoyi-common-core/pom.xml +++ b/ruoyi-common/ruoyi-common-core/pom.xml @@ -17,23 +17,29 @@ - + org.springframework.cloud spring-cloud-starter-openfeign - + + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + - - + + org.springframework spring-context-support - + - - + + org.springframework spring-web - + diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java index 3aafe03..b549d60 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java @@ -237,6 +237,30 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils } /** + * 判断是否为空,并且不是空白字符 + * + * @param str 要判断的value + * @return 结果 + */ + public static boolean hasText(String str) + { + return (str != null && !str.isEmpty() && containsText(str)); + } + + private static boolean containsText(CharSequence str) + { + int strLen = str.length(); + for (int i = 0; i < strLen; i++) + { + if (!Character.isWhitespace(str.charAt(i))) + { + return true; + } + } + return false; + } + + /** * 格式化文本, {} 表示占位符
* 此方法只是简单将占位符 {} 按照顺序替换为参数
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java index 3a44d82..20e20e3 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/aspect/PreAuthorizeAspect.java @@ -11,8 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.PatternMatchUtils; -import org.springframework.util.StringUtils; import com.ruoyi.common.core.exception.PreAuthorizeException; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.security.annotation.PreAuthorize; import com.ruoyi.common.security.service.TokenService; import com.ruoyi.system.api.model.LoginUser; @@ -50,7 +50,7 @@ public class PreAuthorizeAspect return point.proceed(); } - if (!StringUtils.isEmpty(annotation.hasPermi())) + if (StringUtils.isNotEmpty(annotation.hasPermi())) { if (hasPermi(annotation.hasPermi())) { @@ -58,7 +58,7 @@ public class PreAuthorizeAspect } throw new PreAuthorizeException(); } - else if (!StringUtils.isEmpty(annotation.lacksPermi())) + else if (StringUtils.isNotEmpty(annotation.lacksPermi())) { if (lacksPermi(annotation.lacksPermi())) { @@ -74,7 +74,7 @@ public class PreAuthorizeAspect } throw new PreAuthorizeException(); } - else if (!StringUtils.isEmpty(annotation.hasRole())) + else if (StringUtils.isNotEmpty(annotation.hasRole())) { if (hasRole(annotation.hasRole())) { @@ -82,7 +82,7 @@ public class PreAuthorizeAspect } throw new PreAuthorizeException(); } - else if (!StringUtils.isEmpty(annotation.lacksRole())) + else if (StringUtils.isNotEmpty(annotation.lacksRole())) { if (lacksRole(annotation.lacksRole())) { @@ -111,7 +111,7 @@ public class PreAuthorizeAspect public boolean hasPermi(String permission) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) + if (StringUtils.isNull(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) { return false; } @@ -138,7 +138,7 @@ public class PreAuthorizeAspect public boolean hasAnyPermi(String[] permissions) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) + if (StringUtils.isNull(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) { return false; } @@ -162,7 +162,7 @@ public class PreAuthorizeAspect public boolean hasRole(String role) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) + if (StringUtils.isNull(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) { return false; } @@ -196,7 +196,7 @@ public class PreAuthorizeAspect public boolean hasAnyRoles(String[] roles) { LoginUser userInfo = tokenService.getLoginUser(); - if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) + if (StringUtils.isNull(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) { return false; } @@ -220,6 +220,6 @@ public class PreAuthorizeAspect private boolean hasPermissions(Collection authorities, String permission) { return authorities.stream().filter(StringUtils::hasText) - .anyMatch(x -> ALL_PERMISSION.contains(x) || PatternMatchUtils.simpleMatch(permission, x)); + .anyMatch(x -> ALL_PERMISSION.contains(x) || PatternMatchUtils.simpleMatch(x, permission)); } } diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/GatewayConfig.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/GatewayConfig.java index 677ffde..8d0fee4 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/GatewayConfig.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/GatewayConfig.java @@ -1,11 +1,9 @@ package com.ruoyi.gateway.config; -import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; -import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter; import com.ruoyi.gateway.handler.SentinelFallbackHandler; /** @@ -22,11 +20,4 @@ public class GatewayConfig { return new SentinelFallbackHandler(); } - - @Bean - @Order(-1) - public GlobalFilter sentinelGatewayFilter() - { - return new SentinelGatewayFilter(); - } } \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java index 955cbeb..ebfa433 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/RuoYiGenApplication.java @@ -1,7 +1,7 @@ package com.ruoyi.gen; import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.ruoyi.common.security.annotation.EnableCustomConfig; import com.ruoyi.common.security.annotation.EnableRyFeignClients; import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @@ -14,7 +14,7 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @EnableCustomConfig @EnableCustomSwagger2 @EnableRyFeignClients -@SpringCloudApplication +@SpringBootApplication public class RuoYiGenApplication { public static void main(String[] args) diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java index 15a3912..e06d679 100644 --- a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java +++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java @@ -1,7 +1,7 @@ package com.ruoyi.job; import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.ruoyi.common.security.annotation.EnableCustomConfig; import com.ruoyi.common.security.annotation.EnableRyFeignClients; import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @@ -14,7 +14,7 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @EnableCustomConfig @EnableCustomSwagger2 @EnableRyFeignClients -@SpringCloudApplication +@SpringBootApplication public class RuoYiJobApplication { public static void main(String[] args) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java index ee24c93..dfe390f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/RuoYiSystemApplication.java @@ -1,7 +1,7 @@ package com.ruoyi.system; import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.ruoyi.common.security.annotation.EnableCustomConfig; import com.ruoyi.common.security.annotation.EnableRyFeignClients; import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @@ -14,7 +14,7 @@ import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2; @EnableCustomConfig @EnableCustomSwagger2 @EnableRyFeignClients -@SpringCloudApplication +@SpringBootApplication public class RuoYiSystemApplication { public static void main(String[] args) diff --git a/ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/RuoYiMonitorApplication.java b/ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/RuoYiMonitorApplication.java index d0f295e..73628b3 100644 --- a/ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/RuoYiMonitorApplication.java +++ b/ruoyi-visual/ruoyi-monitor/src/main/java/com/ruoyi/modules/monitor/RuoYiMonitorApplication.java @@ -1,8 +1,8 @@ package com.ruoyi.modules.monitor; -import de.codecentric.boot.admin.server.config.EnableAdminServer; import org.springframework.boot.SpringApplication; -import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import de.codecentric.boot.admin.server.config.EnableAdminServer; /** * 监控中心 @@ -10,7 +10,7 @@ import org.springframework.cloud.client.SpringCloudApplication; * @author ruoyi */ @EnableAdminServer -@SpringCloudApplication +@SpringBootApplication public class RuoYiMonitorApplication { public static void main(String[] args)