瀏覽代碼

优化配置

李亚非 3 月之前
父節點
當前提交
4c59c9877e
共有 27 個文件被更改,包括 207 次插入159 次删除
  1. 32 28
      alien-api/src/main/java/shop/alien/api/ApiApplication.java
  2. 9 5
      alien-api/src/main/resources/bootstrap-dev.yml
  3. 4 4
      alien-api/src/main/resources/bootstrap-test.yml
  4. 7 3
      alien-api/src/main/resources/bootstrap.yml
  5. 26 26
      alien-config/src/main/java/shop/alien/config/feign/FeignNacosConfig.java
  6. 7 3
      alien-gateway/src/main/java/shop/alien/gateway/AlienGatewayApplication.java
  7. 9 5
      alien-gateway/src/main/resources/bootstrap-dev.yml
  8. 4 4
      alien-gateway/src/main/resources/bootstrap-test.yml
  9. 5 1
      alien-gateway/src/main/resources/bootstrap.yml
  10. 9 5
      alien-job/src/main/resources/bootstrap-dev.yml
  11. 4 4
      alien-job/src/main/resources/bootstrap-test.yml
  12. 1 1
      alien-job/src/main/resources/bootstrap.yml
  13. 9 5
      alien-lawyer/src/main/resources/bootstrap-dev.yml
  14. 4 4
      alien-lawyer/src/main/resources/bootstrap-test.yml
  15. 1 1
      alien-lawyer/src/main/resources/bootstrap.yml
  16. 34 33
      alien-second/src/main/java/shop/alien/second/AlienSecondApplication.java
  17. 9 5
      alien-second/src/main/resources/bootstrap-dev.yml
  18. 4 4
      alien-second/src/main/resources/bootstrap-test.yml
  19. 1 1
      alien-second/src/main/resources/bootstrap.yml
  20. 2 1
      alien-store-platform/src/main/java/shop/alien/storeplatform/AlienStorePlatformApplication.java
  21. 9 5
      alien-store-platform/src/main/resources/bootstrap-dev.yml
  22. 4 4
      alien-store-platform/src/main/resources/bootstrap-test.yml
  23. 1 1
      alien-store-platform/src/main/resources/bootstrap.yml
  24. 7 3
      alien-store/src/main/resources/bootstrap-dev.yml
  25. 2 2
      alien-store/src/main/resources/bootstrap-test.yml
  26. 1 1
      alien-store/src/main/resources/bootstrap.yml
  27. 2 0
      alien-util/src/main/resources/META-INF/spring.factories

+ 32 - 28
alien-api/src/main/java/shop/alien/api/ApiApplication.java

@@ -1,28 +1,32 @@
-package shop.alien.api;
-
-import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.openfeign.EnableFeignClients;
-import org.springframework.context.annotation.ComponentScan;
-
-@ComponentScan({
-        //配置
-        "cc.xiaokuihua.config.databases",
-        "cc.xiaokuihua.config.feign",
-//        "cc.xiaokuihua.config.filter",
-        "cc.xiaokuihua.config.http",
-        "cc.xiaokuihua.config.redis",
-        //此项目
-        "cc.xiaokuihua.api.*"
-})
-@EnableFeignClients(basePackages = {"cc.xiaokuihua.api.feign"})
-@EnableSwaggerBootstrapUI
-@SpringBootApplication
-public class ApiApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(ApiApplication.class, args);
-    }
-
-}
+package shop.alien.api;
+
+import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Import;
+import shop.alien.util.encryption.JasyptAutoConfiguration;
+
+@ComponentScan({
+        //配置
+        "shop.alien.config.databases",
+        "shop.alien.config.feign",
+        "shop.alien.config.http",
+        "shop.alien.config.redis",
+        //工具类
+        "shop.alien.util.*",
+        //此项目
+        "shop.alien.api.*"
+})
+@Import(JasyptAutoConfiguration.class)
+@EnableFeignClients(basePackages = {"shop.alien.api.feign"})
+@EnableSwaggerBootstrapUI
+@SpringBootApplication
+public class ApiApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ApiApplication.class, args);
+    }
+
+}

+ 9 - 5
alien-api/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-api/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 7 - 3
alien-api/src/main/resources/bootstrap.yml

@@ -1,3 +1,7 @@
-spring:
-  profiles:
-    active: dev
+spring:
+  profiles:
+    active: dev
+
+jasypt:
+  encryptor:
+    bootstrap: true

+ 26 - 26
alien-config/src/main/java/shop/alien/config/feign/FeignNacosConfig.java

@@ -1,26 +1,26 @@
-package shop.alien.config.feign;
-
-import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
-import org.springframework.stereotype.Component;
-
-/**
- * 从 Nacos读取Feign配置
- *
- * @author ssk
- * @version 1.0
- * @date 2025/3/24 14:18
- */
-@Data
-@Component
-@RefreshScope
-public class FeignNacosConfig {
-
-    @Value("${openfeign.timeout.connect}")
-    private int connectTimeout;
-
-    @Value("${openfeign.timeout.read}")
-    private int readTimeout;
-
-}
+package shop.alien.config.feign;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * 从 Nacos读取Feign配置
+ *
+ * @author ssk
+ * @version 1.0
+ * @date 2025/3/24 14:18
+ */
+@Data
+@Component
+@RefreshScope
+public class FeignNacosConfig {
+
+    @Value("${feign.client.config.default.connect-timeout}")
+    private int connectTimeout;
+
+    @Value("${feign.client.config.default.read-timeout}")
+    private int readTimeout;
+
+}

+ 7 - 3
alien-gateway/src/main/java/shop/alien/gateway/AlienGatewayApplication.java

@@ -3,8 +3,11 @@ package shop.alien.gateway;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Import;
+import shop.alien.util.encryption.JasyptAutoConfiguration;
 
 /**
  * 网关
@@ -13,7 +16,8 @@ import org.springframework.context.annotation.ComponentScan;
  * @version 1.0
  * @date 2025/1/21 16:58
  */
-@ComponentScan({"shop.alien.gateway.*"})
+@Import({JacksonAutoConfiguration.class, JasyptAutoConfiguration.class})
+@ComponentScan({"shop.alien.gateway.*"}) // 停止扫描 shop.alien.util.* 以避免 RestTemplate 依赖冲突
 @MapperScan(basePackages = {"shop.alien.gateway.mapper", "shop.alien.mapper"})
 @EnableFeignClients(basePackages = "shop.alien.gateway.feign")
 @SpringBootApplication
@@ -22,10 +26,10 @@ public class AlienGatewayApplication {
     public static void main(String[] args) {
         /*因为Spring Boot本身已经集成了日志框架Logback,而在Alibaba Nacos中又集成了一套Logback框架
         而Alibaba Nacos中的Logback加载要优先于项目自身的Logback框架,在一个项目中其context_name只能定义一次,
-        所以,在项目启动时,Alibaba Nacos的Logback先加载完成后,再加载项目本身的Logback时就出现了冲突,报错误日志 “ Failed to rename context [logback] as [nacos] java.lang.IllegalStateException: Context has been already given a name ” ,但是不影响使用,
+        so,在项目启动时,Alibaba Nacos's Logback先加载完成后,再加载项目本身的Logback时就出现了冲突,报错误日志 “ Failed to rename context [logback] as [nacos] java.lang.IllegalStateException: Context has been already given a name ” ,但是不影响使用,
         解决这个,只要禁用掉其中一个Logback就可以了,一般禁用外部框架夹带的Logback即可*/
         System.setProperty("nacos.logging.default.config.enabled", "false");
         SpringApplication.run(AlienGatewayApplication.class, args);
     }
 
-}
+}

+ 9 - 5
alien-gateway/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-gateway/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 5 - 1
alien-gateway/src/main/resources/bootstrap.yml

@@ -1,3 +1,7 @@
 spring:
   profiles:
-    active: test
+    active: dev
+
+jasypt:
+  encryptor:
+    bootstrap: true

+ 9 - 5
alien-job/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-job/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 1 - 1
alien-job/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: dev

+ 9 - 5
alien-lawyer/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-lawyer/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 1 - 1
alien-lawyer/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: dev

+ 34 - 33
alien-second/src/main/java/shop/alien/second/AlienSecondApplication.java

@@ -1,33 +1,34 @@
-package shop.alien.second;
-
-import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.openfeign.EnableFeignClients;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.scheduling.annotation.EnableScheduling;
-
-//@ComponentScan("shop.alien.second.*")
-@EnableFeignClients(basePackages = {"shop.alien.second.feign"})
-@ComponentScan({
-        "shop.alien.second.*",
-        "shop.alien.util.*",
-        "shop.alien.config.http",
-        "shop.alien.config.databases",
-        "shop.alien.config.feign",
-        "shop.alien.config.properties",
-        "shop.alien.config.redis"})
-@MapperScan({
-        "shop.alien.mapper",
-        "shop.alien.mapper.second"})
-@EnableSwaggerBootstrapUI
-@SpringBootApplication
-@EnableScheduling
-public class AlienSecondApplication {
-
-    public static void main(String[] args) {
-        SpringApplication.run(AlienSecondApplication.class, args);
-    }
-
-}
+package shop.alien.second;
+
+import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+//@ComponentScan("shop.alien.second.*")
+@EnableFeignClients(basePackages = {"shop.alien.second.feign"})
+@ComponentScan({
+        "shop.alien.second.*",
+        "shop.alien.util.*",
+        "shop.alien.config.http",
+        "shop.alien.config.databases",
+        "shop.alien.config.feign",
+        "shop.alien.config.properties",
+        "shop.alien.config.redis",
+        "shop.alien.util.*"})
+@MapperScan({
+        "shop.alien.mapper",
+        "shop.alien.mapper.second"})
+@EnableSwaggerBootstrapUI
+@SpringBootApplication
+@EnableScheduling
+public class AlienSecondApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(AlienSecondApplication.class, args);
+    }
+
+}

+ 9 - 5
alien-second/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-second/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 1 - 1
alien-second/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: dev

+ 2 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/AlienStorePlatformApplication.java

@@ -14,7 +14,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
         "shop.alien.config.http",
         "shop.alien.config.databases",
         "shop.alien.config.properties",
-        "shop.alien.config.redis"})
+        "shop.alien.config.redis",
+        "shop.alien.util.*"})
 @EnableSwaggerBootstrapUI
 @MapperScan({"shop.alien.mapper", "shop.alien.storeplatform.mapper"})
 @SpringBootApplication

+ 9 - 5
alien-store-platform/src/main/resources/bootstrap-dev.yml

@@ -6,16 +6,20 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
 
       #配置中心
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 4 - 4
alien-store-platform/src/main/resources/bootstrap-test.yml

@@ -6,8 +6,8 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
 
@@ -15,8 +15,8 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
-        username: nacos
+        server-addr: 120.26.186.130:8848
+        username: dev
         password: Alien123456
         group: DEFAULT_GROUP
         file-extension: yml

+ 1 - 1
alien-store-platform/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: dev

+ 7 - 3
alien-store/src/main/resources/bootstrap-dev.yml

@@ -6,7 +6,7 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
+        server-addr: 120.26.186.130:8848
         username: nacos
         password: Alien123456
 
@@ -14,8 +14,12 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
+        server-addr: 120.26.186.130:8848
         username: nacos
         password: Alien123456
         group: DEFAULT_GROUP
-        file-extension: yml
+        file-extension: yml
+        shared-configs:
+          - data-id: common.yml
+            group: DEFAULT_GROUP
+            refresh: true

+ 2 - 2
alien-store/src/main/resources/bootstrap-test.yml

@@ -6,7 +6,7 @@ spring:
     nacos:
       #注册中心
       discovery:
-        server-addr: 8.130.79.5:8848
+        server-addr: 120.26.186.130:8848
         username: nacos
         password: Alien123456
         namespace: acd615de-5b62-4d92-996b-740183cd7f15
@@ -15,7 +15,7 @@ spring:
       config:
         enabled: true
         refresh-enabled: true
-        server-addr: 8.130.79.5:8848
+        server-addr: 120.26.186.130:8848
         username: nacos
         password: Alien123456
         group: DEFAULT_GROUP

+ 1 - 1
alien-store/src/main/resources/bootstrap.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: dev

+ 2 - 0
alien-util/src/main/resources/META-INF/spring.factories

@@ -1,2 +1,4 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 shop.alien.util.encryption.JasyptAutoConfiguration
+org.springframework.cloud.bootstrap.BootstrapConfiguration=\
+shop.alien.util.encryption.JasyptAutoConfiguration