dependencyManagement:<dependencyManagement><dependencies><dependency><groupId>com.tencent.cloud</groupId><artifactId>spring-cloud-tencent-dependencies</artifactId><version>${version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
spring-cloud-starter-tencent-all.<dependency><groupId>com.tencent.cloud</groupId><artifactId>spring-cloud-starter-tencent-all</artifactId></dependency>
spring-cloud-starter-tencent-polaris-config.<dependency><groupId>com.tencent.cloud</groupId><artifactId>spring-cloud-starter-tencent-polaris-config</artifactId></dependency>
spring.cloud.polaris.address.spring.cloud.polaris.address to specify the IP address of the registration center cluster, and configure spring.cloud.polaris.config.address to specify the IP address of the configuration center. As shown below:spring.config.import=optional:Polaris needs to be filled in.spring:application:name: ${application.name}config:import: optional:polariscloud:polaris:address: grpc://${replace with the Polaris service address}:8091 # requirednamespace: default # global namespace parameterconfig:address: grpc://${standalone configuration center}:8093 # optional, only required when the configuration center and registration center have different IP addressesauto-refresh: true # optional, when a configuration is published, dynamically refresh the Spring context, default is true
${spring.application.name} in the Polaris control plane. Spring Cloud Tencent Config will automatically inject the configurations under the current application name group:application-${activeProfile}.propertiesapplication-${activeProfile}.ymlapplication-${activeProfile}.yamlapplication.propertiesapplication.ymlapplication.yamlbootstrap-${activeProfile}.propertiesbootstrap-${activeProfile}.ymlbootstrap-${activeProfile}.yamlbootstrap.propertiesbootstrap.ymlbootstrap.yamlspring.cloud.polaris.config.groups in yml, as shown below:spring:cloud:polaris:config:groups:- name: ${spring.application.name} # optional, configuration group for injecting custom configurationsfiles: [ "config/application.properties", "config/bootstrap.yml" ] # List of custom configuration files to inject. When key conflicts occur, the configuration file earlier in the list takes precedence over those later.
@ConfigurationProperties and @Value annotations.@Value is more suitable for scenarios with fewer configurations.@ConfigurationProperties is more suitable for scenarios with a larger number of configurations.@Value injection@Value("${timeout:1000}")private int timeout;
@ConfigurationProperties injection@Component@ConfigurationProperties(prefix = "teacher")public class Person {private String name;private int age;String getName() {return name;}void setName(String name) {this.name = name;}int getAge() {return age;}void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "User{" + "name='" + name + '\\'' + ", age=" + age + '}';}}.
polaris-config-example group in our sample. Place all configuration files for the polaris-config-example application under the polaris-config-example group to facilitate configuration management.module1/file1.properties, module1/file2.yaml, module2/file3.yaml.Spring Cloud Tencent Config is now complete.@Value properties and their corresponding Beans. When property configurations are updated, it identifies all Beans requiring updates and modifies their properties using Java's reflection mechanism.@ConfigurationProperties Bean corresponding to the updated configuration, resulting in a smaller impact scope. For implementation details, see PolarisRefreshAffectedContextRefresher and AffectedConfigurationPropertiesRebinder.@RefreshScope approach to refresh configurations, configure spring.cloud.polaris.config.refresh-type=refresh_context.spring.cloud.polaris.config.auto-refresh=false in bootstrap.yml.Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan