From 437f95311551c35d6379fafc71e3238b9bc24d60 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Tue, 10 Jan 2023 17:35:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:config=E9=AB=98=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../pom.xml | 17 ++++++++++--- .../springcloud/ConfigClientApplication.java | 7 +++--- .../controller/ConfigClientController.java | 10 +++++++- .../src/main/resources/bootstrap.yml | 24 +++++++++++++++++++ .../springcloud/PortalApplicationTests.java | 0 .../src/main/resources/bootstrap.properties | 5 ---- springcloud-service-config/pom.xml | 4 ++++ .../kwan/springcloud/ConfigApplication.java | 2 ++ .../src/main/resources/application.yaml | 8 ++++++- .../src/main/resources/bootstrap.properties | 0 11 files changed, 65 insertions(+), 14 deletions(-) rename {springcloud-service-config-get => springcloud-service-config-client}/pom.xml (71%) rename springcloud-service-config-get/src/main/java/com/kwan/springcloud/ConfigGetApplication.java => springcloud-service-config-client/src/main/java/com/kwan/springcloud/ConfigClientApplication.java (54%) rename springcloud-service-config-get/src/main/java/com/kwan/springcloud/controller/ConfigGetController.java => springcloud-service-config-client/src/main/java/com/kwan/springcloud/controller/ConfigClientController.java (66%) create mode 100644 springcloud-service-config-client/src/main/resources/bootstrap.yml rename {springcloud-service-config-get => springcloud-service-config-client}/src/test/java/com/kwan/springcloud/PortalApplicationTests.java (100%) delete mode 100644 springcloud-service-config-get/src/main/resources/bootstrap.properties delete mode 100644 springcloud-service-config/src/main/resources/bootstrap.properties diff --git a/pom.xml b/pom.xml index 048a005..a5c2f5e 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ springcloud-service-common springcloud-service-portal springcloud-service-config - springcloud-service-config-get + springcloud-service-config-client springcloud-service-feign springcloud-service-eureka diff --git a/springcloud-service-config-get/pom.xml b/springcloud-service-config-client/pom.xml similarity index 71% rename from springcloud-service-config-get/pom.xml rename to springcloud-service-config-client/pom.xml index cce748c..50c837e 100644 --- a/springcloud-service-config-get/pom.xml +++ b/springcloud-service-config-client/pom.xml @@ -7,9 +7,9 @@ springcloud-service-parent 1.0.0 - springcloud-service-config-get + springcloud-service-config-client 0.0.1-SNAPSHOT - springcloud-service-config-get + springcloud-service-config-client 1.8 @@ -27,8 +27,19 @@ org.springframework.cloud - spring-cloud-starter-config + spring-cloud-config-client + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + + org.springframework.boot + spring-boot-starter-actuator + + + diff --git a/springcloud-service-config-get/src/main/java/com/kwan/springcloud/ConfigGetApplication.java b/springcloud-service-config-client/src/main/java/com/kwan/springcloud/ConfigClientApplication.java similarity index 54% rename from springcloud-service-config-get/src/main/java/com/kwan/springcloud/ConfigGetApplication.java rename to springcloud-service-config-client/src/main/java/com/kwan/springcloud/ConfigClientApplication.java index 79ca599..518e360 100644 --- a/springcloud-service-config-get/src/main/java/com/kwan/springcloud/ConfigGetApplication.java +++ b/springcloud-service-config-client/src/main/java/com/kwan/springcloud/ConfigClientApplication.java @@ -2,14 +2,15 @@ package com.kwan.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; - +@EnableEurekaClient @SpringBootApplication -public class ConfigGetApplication { +public class ConfigClientApplication { public static void main(String[] args) { - SpringApplication.run(ConfigGetApplication.class, args); + SpringApplication.run(ConfigClientApplication.class, args); } } diff --git a/springcloud-service-config-get/src/main/java/com/kwan/springcloud/controller/ConfigGetController.java b/springcloud-service-config-client/src/main/java/com/kwan/springcloud/controller/ConfigClientController.java similarity index 66% rename from springcloud-service-config-get/src/main/java/com/kwan/springcloud/controller/ConfigGetController.java rename to springcloud-service-config-client/src/main/java/com/kwan/springcloud/controller/ConfigClientController.java index b2a1634..5e5c580 100644 --- a/springcloud-service-config-get/src/main/java/com/kwan/springcloud/controller/ConfigGetController.java +++ b/springcloud-service-config-client/src/main/java/com/kwan/springcloud/controller/ConfigClientController.java @@ -5,9 +5,17 @@ import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 需要向客户端发送post请求动态刷新才能生效 + * curl -X POST "http://localhost:7002/actuator/refresh" + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/1/10 17:26 + */ @RefreshScope @RestController -class ConfigGetController { +class ConfigClientController { @Value("${from}") private String from; diff --git a/springcloud-service-config-client/src/main/resources/bootstrap.yml b/springcloud-service-config-client/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..51a44db --- /dev/null +++ b/springcloud-service-config-client/src/main/resources/bootstrap.yml @@ -0,0 +1,24 @@ +server: + port: 7002 +spring: + application: + name: didispace + cloud: + config: + label: master #分支名称 + profile: dev #读取后缀名称 + uri: http://localhost:7001/ #配置中心地址k + #上述3个综合:master分支上config-dev.yml的配置文件被读取 + #http://localhost:7001/master/didispace-dev.yml +eureka: + client: + fetch-registry: true + register-with-eureka: true + service-url: + defaultZone: http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/ +management: + endpoints: + web: + exposure: + include: "*" + diff --git a/springcloud-service-config-get/src/test/java/com/kwan/springcloud/PortalApplicationTests.java b/springcloud-service-config-client/src/test/java/com/kwan/springcloud/PortalApplicationTests.java similarity index 100% rename from springcloud-service-config-get/src/test/java/com/kwan/springcloud/PortalApplicationTests.java rename to springcloud-service-config-client/src/test/java/com/kwan/springcloud/PortalApplicationTests.java diff --git a/springcloud-service-config-get/src/main/resources/bootstrap.properties b/springcloud-service-config-get/src/main/resources/bootstrap.properties deleted file mode 100644 index 15cca3d..0000000 --- a/springcloud-service-config-get/src/main/resources/bootstrap.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.application.name=didispace -spring.cloud.config.profile=dev -spring.cloud.config.label=master -spring.cloud.config.uri=http://localhost:7001/ -server.port=7002 \ No newline at end of file diff --git a/springcloud-service-config/pom.xml b/springcloud-service-config/pom.xml index 3f55457..ac531cd 100644 --- a/springcloud-service-config/pom.xml +++ b/springcloud-service-config/pom.xml @@ -23,6 +23,10 @@ org.springframework.cloud spring-cloud-config-server + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + diff --git a/springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java b/springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java index f86619a..b5fad81 100644 --- a/springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java +++ b/springcloud-service-config/src/main/java/com/kwan/springcloud/ConfigApplication.java @@ -3,7 +3,9 @@ package com.kwan.springcloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; +import org.springframework.cloud.netflix.eureka.EnableEurekaClient; +@EnableEurekaClient @EnableConfigServer @SpringBootApplication public class ConfigApplication { diff --git a/springcloud-service-config/src/main/resources/application.yaml b/springcloud-service-config/src/main/resources/application.yaml index bea35a7..ea21a13 100644 --- a/springcloud-service-config/src/main/resources/application.yaml +++ b/springcloud-service-config/src/main/resources/application.yaml @@ -14,4 +14,10 @@ spring: - config-repo username: 13113691357 password: 15671628341qwe - label: master \ No newline at end of file + label: master + +#服务提供者 +eureka: + client: + service-url: + defaultZone: http://eureka8767:8767/eureka/,http://eureka8768:8768/eureka/,http://eureka8769:8769/eureka/ \ No newline at end of file diff --git a/springcloud-service-config/src/main/resources/bootstrap.properties b/springcloud-service-config/src/main/resources/bootstrap.properties deleted file mode 100644 index e69de29..0000000 -- GitLab