Skip to content

Commit fd93ce2

Browse files
committed
fix:fix config refresh.
1 parent a066de2 commit fd93ce2

File tree

21 files changed

+553
-555
lines changed

21 files changed

+553
-555
lines changed

polaris-agent-core/polaris-agent-core-bootstrap-common/src/main/java/cn/polarismesh/agent/core/bootstrap/PolarisInitProperties.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ public class PolarisInitProperties {
55
public void initialize() {
66

77
// ban nacos as sct currently does not support double registration
8-
System.setProperty("spring.cloud.nacos.config.enabled", "false");
98
System.setProperty("spring.cloud.nacos.discovery.enabled", "false");
109

1110
}

polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-a/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.boot.SpringApplication;
2525
import org.springframework.boot.autoconfigure.SpringBootApplication;
2626
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
27-
import org.springframework.cloud.client.serviceregistry.Registration;
2827
import org.springframework.cloud.context.config.annotation.RefreshScope;
2928
import org.springframework.web.bind.annotation.GetMapping;
3029
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,42 +36,42 @@
3736
@SpringBootApplication
3837
public class ProviderApplication {
3938

40-
public static void main(String[] args) {
41-
SpringApplication.run(ProviderApplication.class, args);
42-
}
39+
public static void main(String[] args) {
40+
SpringApplication.run(ProviderApplication.class, args);
41+
}
4342

44-
// @RefreshScope
45-
@RestController
46-
public static class EchoController {
43+
@RefreshScope
44+
@RestController
45+
public static class EchoController {
4746

48-
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
47+
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
4948

50-
@Value("${name:}")
51-
private String name;
49+
@Value("${name:}")
50+
private String name;
5251

53-
@Value("${server.port}")
54-
private String port;
52+
@Value("${server.port}")
53+
private String port;
5554

56-
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
57-
private String ip;
55+
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
56+
private String ip;
5857

59-
@GetMapping("/circuitBreak")
60-
public String circuitBreak() {
61-
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
62-
return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
63-
}
58+
@GetMapping("/circuitBreak")
59+
public String circuitBreak() {
60+
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
61+
return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
62+
}
6463

65-
@GetMapping("/echo/{string}")
66-
public String echo(@PathVariable String string) {
67-
return "Hello, I'm provider, receive msg : "
68-
+ string
69-
+ ", my metadata : "
70-
+ " name config : "
71-
+ name
72-
+ " "
73-
+ port;
74-
}
64+
@GetMapping("/echo/{string}")
65+
public String echo(@PathVariable String string) {
66+
return "Hello, I'm provider, receive msg : "
67+
+ string
68+
+ ", my metadata : "
69+
+ " name config : "
70+
+ name
71+
+ " "
72+
+ port;
73+
}
7574

76-
}
75+
}
7776

7877
}

polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2022-examples/quickstart-examples/provider-b/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.boot.SpringApplication;
2525
import org.springframework.boot.autoconfigure.SpringBootApplication;
2626
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
27-
import org.springframework.cloud.client.serviceregistry.Registration;
2827
import org.springframework.cloud.context.config.annotation.RefreshScope;
2928
import org.springframework.http.HttpStatus;
3029
import org.springframework.http.ResponseEntity;
@@ -39,42 +38,42 @@
3938
@SpringBootApplication
4039
public class ProviderApplication {
4140

42-
public static void main(String[] args) {
43-
SpringApplication.run(ProviderApplication.class, args);
44-
}
41+
public static void main(String[] args) {
42+
SpringApplication.run(ProviderApplication.class, args);
43+
}
4544

46-
// @RefreshScope
47-
@RestController
48-
public static class EchoController {
45+
@RefreshScope
46+
@RestController
47+
public static class EchoController {
4948

50-
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
49+
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
5150

52-
@Value("${name:}")
53-
private String name;
51+
@Value("${name:}")
52+
private String name;
5453

55-
@Value("${server.port}")
56-
private String port;
54+
@Value("${server.port}")
55+
private String port;
5756

58-
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
59-
private String ip;
57+
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
58+
private String ip;
6059

61-
@GetMapping("/circuitBreak")
62-
public ResponseEntity<String> circuitBreak() throws InterruptedException {
63-
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
64-
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY);
65-
}
60+
@GetMapping("/circuitBreak")
61+
public ResponseEntity<String> circuitBreak() throws InterruptedException {
62+
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
63+
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY);
64+
}
6665

67-
@GetMapping("/echo/{string}")
68-
public String echo(@PathVariable String string) {
69-
return "Hello, I'm provider, receive msg : "
70-
+ string
71-
+ ", my metadata : "
72-
+ " name config : "
73-
+ name
74-
+ " "
75-
+ port;
76-
}
66+
@GetMapping("/echo/{string}")
67+
public String echo(@PathVariable String string) {
68+
return "Hello, I'm provider, receive msg : "
69+
+ string
70+
+ ", my metadata : "
71+
+ " name config : "
72+
+ name
73+
+ " "
74+
+ port;
75+
}
7776

78-
}
77+
}
7978

8079
}

polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ConsumerApplication.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import org.springframework.beans.factory.annotation.Value;
2121
import org.springframework.boot.SpringApplication;
22+
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
2223
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
2325
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
2426
import org.springframework.cloud.client.serviceregistry.Registration;
2527
import org.springframework.cloud.context.config.annotation.RefreshScope;
@@ -37,34 +39,35 @@
3739
@SpringBootApplication
3840
public class ConsumerApplication {
3941

40-
public static void main(String[] args) {
41-
SpringApplication.run(ConsumerApplication.class, args);
42-
}
42+
public static void main(String[] args) {
43+
SpringApplication.run(ConsumerApplication.class, args);
44+
}
4345

44-
@LoadBalanced
45-
@Bean
46-
public RestTemplate restTemplate() {
47-
return new RestTemplate();
48-
}
46+
@LoadBalanced
47+
@Bean
48+
public RestTemplate restTemplate() {
49+
return new RestTemplate();
50+
}
4951

50-
@RestController
51-
@RefreshScope
52-
public static class EchoController {
52+
@RestController
53+
@RefreshScope
54+
@ImportAutoConfiguration(RefreshAutoConfiguration.class)
55+
public static class EchoController {
5356

54-
private Registration registration;
57+
private Registration registration;
5558

56-
private RestTemplate template;
59+
private RestTemplate template;
5760

58-
@Value("${server.port}")
59-
private int port;
61+
@Value("${server.port}")
62+
private int port;
6063

61-
@Value("${custom.config:none}")
62-
private String customConfig;
64+
@Value("${custom.config:none}")
65+
private String customConfig;
6366

64-
public EchoController(RestTemplate restTemplate, Registration registration) {
65-
this.template = restTemplate;
66-
this.registration = registration;
67-
}
67+
public EchoController(RestTemplate restTemplate, Registration registration) {
68+
this.template = restTemplate;
69+
this.registration = registration;
70+
}
6871

6972
// @GetMapping("/echo/{str}")
7073
// public ResponseEntity<String> rest(@PathVariable String str) {
@@ -75,18 +78,18 @@ public EchoController(RestTemplate restTemplate, Registration registration) {
7578
// return new ResponseEntity<>(content, HttpStatus.OK);
7679
// }
7780

78-
@GetMapping("/echo/{str}")
79-
public ResponseEntity<String> rest(@PathVariable String str) {
80-
ResponseEntity<String> response = template.getForEntity("http://service-provider-2023/echo/" + str,
81-
String.class);
82-
return response;
83-
}
81+
@GetMapping("/echo/{str}")
82+
public ResponseEntity<String> rest(@PathVariable String str) {
83+
ResponseEntity<String> response = template.getForEntity("http://service-provider-2023/echo/" + str,
84+
String.class);
85+
return response;
86+
}
8487

85-
@GetMapping("/custom/config")
86-
public ResponseEntity<String> getCustomConfig() {
87-
return new ResponseEntity<>(String.valueOf(customConfig), HttpStatus.OK);
88-
}
88+
@GetMapping("/custom/config")
89+
public ResponseEntity<String> getCustomConfig() {
90+
return new ResponseEntity<>(String.valueOf(customConfig), HttpStatus.OK);
91+
}
8992

90-
}
93+
}
9194

9295
}

polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-2023-examples/quickstart-examples/consumer/src/main/resources/bootstrap.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ spring.cloud.nacos.discovery.enabled=true
88
spring.cloud.nacos.config.enabled=true
99
spring.cloud.nacos.username=nacos
1010
spring.cloud.nacos.password=nacos
11-
1211
spring.cloud.loadbalancer.nacos.enabled=true
1312
# use feign client in GraalVM environment need to set below config
14-
spring.cloud.refresh.enabled=false
1513
spring.main.allow-circular-references=true
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server.port=65001
2-
spring.application.name=service-provider-2022
2+
spring.application.name=service-provider-2023
33
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
44
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
55
spring.cloud.nacos.config.enabled=true
@@ -9,10 +9,8 @@ spring.cloud.nacos.discovery.enabled=true
99
#spring.cloud.nacos.discovery.ip-type=IPv4
1010
#only register IPv6 instance
1111
#spring.cloud.nacos.discovery.ip-type=IPv6
12-
1312
spring.cloud.nacos.username=nacos
1413
spring.cloud.nacos.password=nacos
15-
1614
management.endpoints.web.exposure.include=*
1715
management.endpoint.health.show-details=always
1816
spring.main.allow-circular-references=true

polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/provider-a/src/main/java/cn/polarismesh/agent/examples/alibaba/cloud/cloud/ProviderApplication.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.boot.SpringApplication;
2525
import org.springframework.boot.autoconfigure.SpringBootApplication;
2626
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
27-
import org.springframework.cloud.client.serviceregistry.Registration;
2827
import org.springframework.cloud.context.config.annotation.RefreshScope;
2928
import org.springframework.web.bind.annotation.GetMapping;
3029
import org.springframework.web.bind.annotation.PathVariable;
@@ -37,42 +36,42 @@
3736
@SpringBootApplication
3837
public class ProviderApplication {
3938

40-
public static void main(String[] args) {
41-
SpringApplication.run(ProviderApplication.class, args);
42-
}
39+
public static void main(String[] args) {
40+
SpringApplication.run(ProviderApplication.class, args);
41+
}
4342

44-
// @RefreshScope
45-
@RestController
46-
public static class EchoController {
43+
@RefreshScope
44+
@RestController
45+
public static class EchoController {
4746

48-
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
47+
private static final Logger LOG = LoggerFactory.getLogger(ProviderApplication.class);
4948

50-
@Value("${name:}")
51-
private String name;
49+
@Value("${name:}")
50+
private String name;
5251

53-
@Value("${server.port}")
54-
private String port;
52+
@Value("${server.port}")
53+
private String port;
5554

56-
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
57-
private String ip;
55+
@Value("${spring.cloud.client.ip-address:127.0.0.1}")
56+
private String ip;
5857

59-
@GetMapping("/circuitBreak")
60-
public String circuitBreak() {
61-
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
62-
return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
63-
}
58+
@GetMapping("/circuitBreak")
59+
public String circuitBreak() {
60+
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
61+
return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
62+
}
6463

65-
@GetMapping("/echo/{string}")
66-
public String echo(@PathVariable String string) {
67-
return "Hello, I'm provider, receive msg : "
68-
+ string
69-
+ ", my metadata : "
70-
+ " name config : "
71-
+ name
72-
+ " "
73-
+ port;
74-
}
64+
@GetMapping("/echo/{string}")
65+
public String echo(@PathVariable String string) {
66+
return "Hello, I'm provider, receive msg : "
67+
+ string
68+
+ ", my metadata : "
69+
+ " name config : "
70+
+ name
71+
+ " "
72+
+ port;
73+
}
7574

76-
}
75+
}
7776

7877
}

0 commit comments

Comments
 (0)