lixueqiang пре 2 година
родитељ
комит
05a16198d5

+ 5 - 0
docker-compose.yml

@@ -34,6 +34,11 @@ services:
       - MYSQL_SERVICE_USER=root
       - MYSQL_SERVICE_PASSWORD=root
       - MYSQL_SERVICE_DB_NAME=kxs_config
+      # 开启鉴权
+      - NACOS_AUTH_ENABLE=true
+      - NACOS_AUTH_IDENTITY_KEY=2222
+      - NACOS_AUTH_IDENTITY_VALUE=2xxx
+      - NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
     volumes:
       - ./logs/nacos:/home/nacos/logs
     ports:

+ 26 - 0
kxs-common/kxs-common-core/src/main/java/com/kxs/common/core/constant/ServiceNameConstants.java

@@ -0,0 +1,26 @@
+
+
+package com.kxs.common.core.constant;
+
+
+/**
+ * 服务名称
+ *
+ * @author Lxq
+ * @date 2023-12-04
+ */
+public interface ServiceNameConstants {
+
+	String CLIENT_NAME = "http://";
+
+	/**
+	 * 系统模块
+	 */
+	String SYSTEM_SERVICE = "kxs-system-biz";
+
+	/**
+	 * USER模块
+	 */
+	String USER_SERVICE = "kxs-user-biz";
+
+}

+ 5 - 4
kxs-gateway/src/main/java/com/kxs/gateway/api/config/AesCryptoConfig.java

@@ -4,6 +4,7 @@ import cn.hutool.crypto.symmetric.AES;
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
 
 /**
  * 对称加密配置类
@@ -11,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
  * @author Lxq
  * @date 2023-11-03
  */
-@Configuration
+@Configuration(proxyBeanMethods = false)
 @RequiredArgsConstructor
 public class AesCryptoConfig {
 
@@ -25,11 +26,11 @@ public class AesCryptoConfig {
 	 */
 	@Bean
 	public AES cryptoAes() {
-		return new AES(configProperties.getEncodeMode(), configProperties.getEncodePadding(),
+		return new AES(configProperties.getAes().getEncodeMode(), configProperties.getAes().getEncodePadding(),
 				// 密钥,可以自定义
-				configProperties.getEncodeKey().getBytes(),
+				configProperties.getAes().getEncodeKey().getBytes(),
 				// iv加盐,按照实际需求添加
-				configProperties.getEncodeIv().getBytes());
+				configProperties.getAes().getEncodeIv().getBytes());
 	}
 
 }

+ 14 - 11
kxs-gateway/src/main/java/com/kxs/gateway/api/config/GatewayConfigProperties.java

@@ -18,20 +18,23 @@ import java.util.List;
 @ConfigurationProperties("gateway")
 public class GatewayConfigProperties {
 
-	/**
-	 * 网关解密 秘钥 {@link com.kxs.gateway.api.filter.RequestDecoderFilter}
-	 */
-	@Value("${gateway.aes.encode-key}")
-	private String encodeKey;
+	private AesConfigProperties aes = new AesConfigProperties();
+
+	@Data
+	public static class AesConfigProperties {
+
+		/**
+		 * 网关解密 秘钥 {@link com.kxs.gateway.api.filter.RequestDecoderFilter}
+		 */
+		private String encodeKey;
+
+		private String encodeIv;
 
-	@Value("${gateway.aes.encode-iv}")
-	private String encodeIv;
+		private String encodeMode;
 
-	@Value("${gateway.aes.encode-mode}")
-	private String encodeMode;
+		private String encodePadding;
 
-	@Value("${gateway.aes.encode-padding}")
-	private String encodePadding;
+	}
 
 	/**
 	 * 网关不需要校验验证码的客户端 {@link com.kxs.gateway.api.filter.ValidateCodeGatewayFilter}

+ 0 - 1
kxs-gateway/src/main/java/com/kxs/gateway/api/filter/ValidateCodeGatewayFilter.java

@@ -57,7 +57,6 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory<Obje
 			if (!isAuthToken || isRefreshTokenRequest(request)) {
 				return chain.filter(exchange);
 			}
-
 			boolean isIgnoreClient = configProperties.getIgnoreClients().contains(WebUtils.getClientId(request));
 			try {
 				if (!isIgnoreClient) {

+ 0 - 13
kxs-gateway/src/main/resources/application-dev.yml

@@ -1,13 +0,0 @@
-spring:
-  cloud:
-    discovery:
-      client:
-        simple:
-          instances:
-            kxs-system-biz: #负载均衡
-              - uri: http://127.0.0.1:8888
-            kxs-codegen:
-              - uri: http://127.0.0.1:4002
-            kxs-quartz:
-              - uri: http://127.0.0.1:4000
-

+ 15 - 74
kxs-gateway/src/main/resources/application.yml

@@ -1,81 +1,22 @@
 
 server:
   port: 9999
+
 spring:
-  profiles:
-    active: @profiles.active@
   application:
     name: @artifactId@
   cloud:
-    gateway:
-      routes:
-        #ADMIN 模块
-        - id: kxs-system-biz  # 唯一的服务ID
-          uri: lb://kxs-system-biz # instances下的服务名称,实现负载均衡
-          predicates:
-            - Path=/v1/kxs/admin/** #当前服务的请求前缀,
-          filters:
-            # 过滤前缀
-            - StripPrefix=3
-            # 限流配置
-            - name: RequestRateLimiter
-              args:
-                key-resolver: '#{@remoteAddrKeyResolver}' #SPEL表达式去的对应的bean
-                redis-rate-limiter.replenishRate: 100 # 令牌桶每秒填充平均速率
-                redis-rate-limiter.burstCapacity: 200 # 令牌桶总容量
-            # 验证码处理
-            - ValidateCodeGatewayFilter #如果该服务需要验证码则开启此过滤器
-            # 解密过滤器
-            - RequestDecoderFilter
-
-        # 代码生成模块
-        - id: kxs-codegen
-          uri: lb://kxs-codegen
-          predicates:
-            - Path=/v1/kxs/gen/**
-          filters:
-            # 过滤前缀
-            - StripPrefix=3
-            # 解密过滤器
-            - RequestDecoderFilter
-
-        # 定时任务成模块
-        - id: kxs-quartz
-          uri: lb://kxs-quartz
-          predicates:
-            - Path=/v1/kxs/job/**
-          filters:
-            # 过滤前缀
-            - StripPrefix=3
-            # 解密过滤器
-            - RequestDecoderFilter
-
-        # 固定路由转发配置 无修改
-        - id: openapi
-          uri: lb://sky-gateway
-          predicates:
-            - Path=/v3/api-docs/**
-          filters:
-            - RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/$\{path}/v3/api-docs
-
-knife4j:
-  gateway:
-    enabled: true
-    tags-sorter: order
-    operations-sorter: order
-    strategy: manual
-    routes:
-      - name: 权限管理
-        url: /v1/kxs/admin/v3/api-docs?group=default
-        service-name: system
-        context-path: /admin
-
-gateway:
-  aes:
-    encode-key: 'CBTU1dD4Kd5pyiGWTsI10jRQ3SvKusSV'
-    encode-iv: 'DYgjCEIMVrj2W9xN'
-    encode-mode: 'CBC'
-    encode-padding: 'PKCS7Padding'
-  #不校验验证码的客户端
-  ignore-clients:
-    - kxs
+    nacos:
+      username: @nacos.username@
+      password: @nacos.password@
+      discovery:
+        server-addr: ${NACOS_HOST:kxs-register}:${NACOS_PORT:8848}
+        watch:
+          enabled: true
+        watch-delay: 1000
+      config:
+        server-addr: ${spring.cloud.nacos.discovery.server-addr}
+  config:
+    import:
+      - optional:nacos:application-@profiles.active@.yml
+      - optional:nacos:${spring.application.name}-@profiles.active@.yml

+ 0 - 10
kxs-quartz/src/main/resources/application-dev.yml

@@ -1,10 +0,0 @@
-
-spring:
-  datasource:
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs_job?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-
-

+ 0 - 10
kxs-quartz/src/main/resources/application-prod.yml

@@ -1,10 +0,0 @@
-
-spring:
-  datasource:
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs_job?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-
-

+ 0 - 10
kxs-quartz/src/main/resources/application-test.yml

@@ -1,10 +0,0 @@
-
-spring:
-  datasource:
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs_job?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-
-

+ 12 - 30
kxs-quartz/src/main/resources/application.yml

@@ -4,34 +4,16 @@ server:
 spring:
   application:
     name: @artifactId@
-  profiles:
-    active: @profiles.active@
-  quartz:
-    #相关属性配置
-    properties:
-      org:
-        quartz:
-          scheduler:
-            instanceName: clusteredScheduler
-            instanceId: AUTO
-          jobStore:
-            class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
-            driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
-            tablePrefix: QRTZ_
-            isClustered: true
-            clusterCheckinInterval: 10000
-            useProperties: false
-          threadPool:
-            class: org.quartz.simpl.SimpleThreadPool
-            threadCount: 50
-            threadPriority: 5
-            threadsInheritContextClassLoaderOfInitializingThread: true
-    #数据库方式
-    job-store-type: jdbc
-    #初始化表结构
-    #jdbc:
-    #initialize-schema: never
-  web:
-    resources:
-      static-locations: classpath:/static/,classpath:/views/
+  cloud:
+    nacos:
+      username: @nacos.username@
+      password: @nacos.password@
+      discovery:
+        server-addr: ${NACOS_HOST:kxs-register}:${NACOS_PORT:8848}
+      config:
+        server-addr: ${spring.cloud.nacos.discovery.server-addr}
+  config:
+    import:
+      - nacos:application-@profiles.active@.yml
+      - nacos:${spring.application.name}-@profiles.active@.yml
 

+ 10 - 0
kxs-system/kxs-system-api/pom.xml

@@ -34,5 +34,15 @@
             <groupId>com.kxs</groupId>
             <artifactId>kxs-common-mybatis</artifactId>
         </dependency>
+        <!-- LB 扩展 -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
+        </dependency>
+        <!--caffeine 替换LB 默认缓存实现-->
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 15 - 5
kxs-system/kxs-system-api/src/main/java/com/kxs/system/api/feign/config/AdminFeignClientConfiguration.java

@@ -1,9 +1,12 @@
 package com.kxs.system.api.feign.config;
 
+import cn.hutool.core.text.CharSequenceUtil;
 import cn.hutool.core.util.StrUtil;
+import com.kxs.common.core.constant.ServiceNameConstants;
 import com.kxs.system.api.feign.*;
 import jakarta.servlet.http.HttpServletRequest;
 import lombok.RequiredArgsConstructor;
+import org.springframework.cloud.client.loadbalancer.reactive.ReactorLoadBalancerExchangeFilterFunction;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.http.HttpHeaders;
@@ -16,7 +19,9 @@ import org.springframework.web.service.invoker.HttpServiceProxyFactory;
 
 /**
  * <p>
- * 当前服务的webClient配置 服务下的远程调用统一在此配置
+ * 当前服务的webClient配置
+ * 服务下的远程调用统一在此配置
+ * 使用注册中心 需配置远程调用器 以实现负载均衡
  * </p>
  *
  * @author 没秃顶的码农
@@ -26,7 +31,12 @@ import org.springframework.web.service.invoker.HttpServiceProxyFactory;
 @RequiredArgsConstructor
 public class AdminFeignClientConfiguration {
 
-	private static final String ADMIN_SERVICE = "http://localhost:8888";
+	/**
+	 * 负载均衡器
+	 */
+	private final ReactorLoadBalancerExchangeFilterFunction reactorLoadBalancerExchangeFilterFunction;
+
+	private static final String SERVICE_NAME = ServiceNameConstants.CLIENT_NAME + ServiceNameConstants.SYSTEM_SERVICE;
 
 	@Bean
 	public WebClient oauthRequestInterceptor() {
@@ -42,14 +52,14 @@ public class AdminFeignClientConfiguration {
 				if (requestAttributes != null) {
 					HttpServletRequest httpServletRequest = requestAttributes.getRequest();
 					String token = httpServletRequest.getHeader(HttpHeaders.AUTHORIZATION);
-					if (!StrUtil.isBlank(token)) {
+					if (!CharSequenceUtil.isBlank(token)) {
 						// 传递token
 						filtered.header(HttpHeaders.AUTHORIZATION, token);
 					}
 				}
 				return next.exchange(filtered.build());
-			})
-			.baseUrl(ADMIN_SERVICE)
+			}).filter(reactorLoadBalancerExchangeFilterFunction)
+			.baseUrl(SERVICE_NAME)
 			.build();
 	}
 

+ 10 - 0
kxs-system/kxs-system-biz/pom.xml

@@ -19,6 +19,16 @@
     </properties>
 
     <dependencies>
+        <!--注册中心客户端-->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+        </dependency>
+        <!--配置中心客户端-->
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+        </dependency>
         <!--undertow容器-->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 0 - 26
kxs-system/kxs-system-biz/src/main/resources/application-dev.yml

@@ -1,26 +0,0 @@
-
-spring:
-  data:
-    redis:
-      host: localhost
-      repositories:
-        enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度\
-  datasource:
-#    query-ds-sql: 'select * from sys_datasource_conf where del_flag = 0' #动态数据源配置表
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-    #hikari数据源特性配置
-    hikari:
-      maximum-pool-size: 50 #最大连接数,默认值10.
-      minimum-idle: 20 #最小空闲连接,默认值10.
-      connection-timeout: 60000 #连接超时时间(毫秒),默认值30秒.
-      #空闲连接超时时间,默认值600000(10分钟),只有空闲连接数大于最大连接数且空闲时间超过该值,才会被释放
-      #如果大于等于 max-lifetime 且 max-lifetime>0,则会被重置为0.
-      idle-timeout: 600000
-      max-lifetime: 3000000 #连接最大存活时间,默认值30分钟.设置应该比mysql设置的超时时间短
-      connection-test-query: select 1 #连接测试查询
-
-

+ 0 - 15
kxs-system/kxs-system-biz/src/main/resources/application-prod.yml

@@ -1,15 +0,0 @@
-
-spring:
-  data:
-    redis:
-      host: localhost
-      repositories:
-        enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度\
-  datasource:
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-
-

+ 0 - 15
kxs-system/kxs-system-biz/src/main/resources/application-test.yml

@@ -1,15 +0,0 @@
-
-spring:
-  data:
-    redis:
-      host: localhost
-      repositories:
-        enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度\
-  datasource:
-    type: com.zaxxer.hikari.HikariDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    username: root
-    password: root
-    url: jdbc:mysql://localhost:3306/kxs?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
-
-

+ 13 - 34
kxs-system/kxs-system-biz/src/main/resources/application.yml

@@ -2,44 +2,23 @@ server:
   port: 8888
 
 spring:
-  profiles:
-    active: @profiles.active@
   application:
     name: @artifactId@
-  cache:
-    type: redis
-  # Servlet 配置
-  servlet:
-    # 文件上传相关配置项
-    multipart:
-      max-file-size: 16MB # 单个文件大小
-      max-request-size: 32MB # 设置总上传的文件大小
+  cloud:
+    nacos:
+      username: @nacos.username@
+      password: @nacos.password@
+      discovery:
+        server-addr: ${NACOS_HOST:kxs-register}:${NACOS_PORT:8848}
+      config:
+        server-addr: ${spring.cloud.nacos.discovery.server-addr}
+  config:
+    import:
+      - nacos:application-@profiles.active@.yml
+      - nacos:${spring.application.name}-@profiles.active@.yml
+
 
-# swagger 配置
-swagger:
-  enabled: true
-  title: 客小爽API
-  gateway: http://${GATEWAY_HOST:localhost}:${GATEWAY-PORT:9999}
-  token-url: ${swagger.gateway}/v1/kxs/admin/oauth2/token
-  scope: server
-  services:
-    kxs-system-biz: admin
-    sky-codegen: gen
 
-# mybaits-plus配置
-mybatis-plus:
-  mapper-locations: classpath*:/mapper/*.xml
-  global-config:
-    banner: false # 关闭控制台的 Banner 打印
-    db-config:
-      id-type: auto
-      table-underline: true
-      logic-delete-value: 1  # 逻辑已删除值(默认为 1)
-      logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
-  type-handlers-package: com.kxs.common.mybatis.handler
-  configuration:
-    map-underscore-to-camel-case: true
-    shrink-whitespaces-in-sql: true
 
 
 

+ 6 - 0
pom.xml

@@ -324,6 +324,8 @@
             <properties>
                 <!-- 环境标识,需要与配置文件的名称相对应 -->
                 <profiles.active>dev</profiles.active>
+                <nacos.username>nacos</nacos.username>
+                <nacos.password>nacos</nacos.password>
             </properties>
             <activation>
                 <!-- 默认环境 -->
@@ -335,6 +337,8 @@
             <properties>
                 <!-- 环境标识,需要与配置文件的名称相对应 -->
                 <profiles.active>test</profiles.active>
+                <nacos.username>nacos</nacos.username>
+                <nacos.password>nacos</nacos.password>
             </properties>
             <activation>
                 <!-- 默认环境 -->
@@ -346,6 +350,8 @@
             <properties>
                 <!-- 环境标识,需要与配置文件的名称相对应 -->
                 <profiles.active>prod</profiles.active>
+                <nacos.username>nacos</nacos.username>
+                <nacos.password>nacos</nacos.password>
             </properties>
             <activation>
                 <!-- 默认环境 -->