fix not load application.yml bug & fix guava version conflict bug (#286)

greenwich
lepdou 2 years ago committed by Haotian Zhang
parent 710b5e33a4
commit c88bdaa944

@ -1,5 +1,4 @@
# Change Log # Change Log
--- ---
- [Add metadata transfer example.](https://github.com/Tencent/spring-cloud-tencent/pull/209) - [fix: fix not load application.yml bug & fix guava version conflict bug.](https://github.com/Tencent/spring-cloud-tencent/pull/286)
- [feat:merge features from 1.5.2-Hoxton.SR9.](https://github.com/Tencent/spring-cloud-tencent/pull/223)

@ -0,0 +1,5 @@
# Change Log
---
- [fix:use 1.6.1 version of polaris-java.](https://github.com/Tencent/spring-cloud-tencent/pull/209)
- [fix:use 1.6.1 version of polaris-java and fix some bug.](https://github.com/Tencent/spring-cloud-tencent/pull/223)

@ -38,9 +38,11 @@
</scm> </scm>
<modules> <modules>
<module>spring-cloud-tencent-polaris-context</module>
<module>spring-cloud-tencent-commons</module> <module>spring-cloud-tencent-commons</module>
<module>spring-cloud-tencent-polaris-context</module>
<module>spring-cloud-tencent-polaris-loadbalancer</module>
<module>spring-cloud-starter-tencent-metadata-transfer</module> <module>spring-cloud-starter-tencent-metadata-transfer</module>
<module>spring-cloud-starter-tencent-polaris-config</module>
<module>spring-cloud-starter-tencent-polaris-discovery</module> <module>spring-cloud-starter-tencent-polaris-discovery</module>
<module>spring-cloud-starter-tencent-polaris-ratelimit</module> <module>spring-cloud-starter-tencent-polaris-ratelimit</module>
<module>spring-cloud-starter-tencent-polaris-circuitbreaker</module> <module>spring-cloud-starter-tencent-polaris-circuitbreaker</module>
@ -48,8 +50,6 @@
<module>spring-cloud-tencent-dependencies</module> <module>spring-cloud-tencent-dependencies</module>
<module>spring-cloud-tencent-examples</module> <module>spring-cloud-tencent-examples</module>
<module>spring-cloud-tencent-coverage</module> <module>spring-cloud-tencent-coverage</module>
<module>spring-cloud-starter-tencent-polaris-config</module>
<module>spring-cloud-tencent-polaris-loadbalancer</module>
</modules> </modules>
<developers> <developers>
@ -86,7 +86,7 @@
<properties> <properties>
<!-- Project revision --> <!-- Project revision -->
<revision>1.5.2-Greenwich.SR6</revision> <revision>1.5.3-Greenwich.SR6</revision>
<!-- Spring Cloud --> <!-- Spring Cloud -->
<spring.cloud.version>Greenwich.SR6</spring.cloud.version> <spring.cloud.version>Greenwich.SR6</spring.cloud.version>

@ -19,9 +19,10 @@
package com.tencent.cloud.metadata.core.intercepter; package com.tencent.cloud.metadata.core.intercepter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import com.tencent.cloud.common.constant.MetadataConstant; import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
import com.tencent.cloud.metadata.core.EncodeTransferMedataFeignInterceptor; import com.tencent.cloud.metadata.core.EncodeTransferMedataFeignInterceptor;
import feign.RequestInterceptor; import feign.RequestInterceptor;
@ -62,10 +63,9 @@ public class EncodeTransferMedataFeignInterceptorTest {
private TestApplication.TestFeign testFeign; private TestApplication.TestFeign testFeign;
@Test @Test
public void test1() { public void testTransitiveMetadataFromApplicationConfig() {
String metadata = testFeign.test(); String metadata = testFeign.test();
Assertions.assertThat(metadata) Assertions.assertThat(metadata).isEqualTo("2");
.isEqualTo("{\"b\":\"2\"}");
Assertions.assertThat(metadataLocalProperties.getContent().get("a")) Assertions.assertThat(metadataLocalProperties.getContent().get("a"))
.isEqualTo("1"); .isEqualTo("1");
Assertions.assertThat(metadataLocalProperties.getContent().get("b")) Assertions.assertThat(metadataLocalProperties.getContent().get("b"))
@ -81,16 +81,13 @@ public class EncodeTransferMedataFeignInterceptorTest {
public String test( public String test(
@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String customMetadataStr) @RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String customMetadataStr)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
return URLDecoder.decode(customMetadataStr, "UTF-8"); return MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_TRANSITIVE, "b");
} }
@FeignClient(name = "test-feign", url = "http://localhost:8081") @FeignClient(name = "test-feign", url = "http://localhost:8081")
public interface TestFeign { public interface TestFeign {
@RequestMapping(value = "/test", @RequestMapping("/test")
headers = {"X-SCT-Metadata-Transitive-a=11",
"X-SCT-Metadata-Transitive-b=22",
"X-SCT-Metadata-Transitive-c=33"})
String test(); String test();
} }

@ -19,11 +19,12 @@
package com.tencent.cloud.metadata.core.intercepter; package com.tencent.cloud.metadata.core.intercepter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import com.tencent.cloud.common.constant.MetadataConstant; import com.tencent.cloud.common.constant.MetadataConstant;
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; import com.tencent.cloud.common.metadata.MetadataContext;
import com.tencent.cloud.common.metadata.MetadataContextHolder;
import com.tencent.cloud.metadata.core.EncodeTransferMedataRestTemplateInterceptor; import com.tencent.cloud.metadata.core.EncodeTransferMedataRestTemplateInterceptor;
import org.assertj.core.api.Assertions;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -32,6 +33,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -51,9 +55,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
properties = { "spring.config.location = classpath:application-test.yml" }) properties = { "spring.config.location = classpath:application-test.yml" })
public class EncodeTransferMedataRestTemplateInterceptorTest { public class EncodeTransferMedataRestTemplateInterceptorTest {
@Autowired
private MetadataLocalProperties metadataLocalProperties;
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
@ -61,30 +62,14 @@ public class EncodeTransferMedataRestTemplateInterceptorTest {
private int localServerPort; private int localServerPort;
@Test @Test
public void test1() { public void testTransitiveMetadataFromApplicationConfig() {
// HttpHeaders httpHeaders = new HttpHeaders(); HttpHeaders httpHeaders = new HttpHeaders();
// httpHeaders.set(MetadataConstant.HeaderName.CUSTOM_METADATA, HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
// "{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}"); String metadata = restTemplate
// HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders); .exchange("http://localhost:" + localServerPort + "/test", HttpMethod.GET,
// String metadata = restTemplate httpEntity, String.class)
// .exchange("http://localhost:" + localServerPort + "/test", HttpMethod.GET, .getBody();
// httpEntity, String.class) Assertions.assertThat(metadata).isEqualTo("2");
// .getBody();
// Assertions.assertThat(metadata)
// .isEqualTo("{\"a\":\"11\",\"b\":\"22\",\"c\":\"33\"}");
// Assertions.assertThat(metadataLocalProperties.getContent().get("a"))
// .isEqualTo("1");
// Assertions.assertThat(metadataLocalProperties.getContent().get("b"))
// .isEqualTo("2");
// Assertions
// .assertThat(MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_TRANSITIVE, "a"))
// .isEqualTo("11");
// Assertions
// .assertThat(MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_TRANSITIVE, "b"))
// .isEqualTo("22");
// Assertions
// .assertThat(MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_TRANSITIVE, "c"))
// .isEqualTo("33");
} }
@SpringBootApplication @SpringBootApplication
@ -100,7 +85,7 @@ public class EncodeTransferMedataRestTemplateInterceptorTest {
public String test( public String test(
@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String customMetadataStr) @RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String customMetadataStr)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
return URLDecoder.decode(customMetadataStr, "UTF-8"); return MetadataContextHolder.get().getContext(MetadataContext.FRAGMENT_TRANSITIVE, "b");
} }
} }

@ -11,6 +11,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
<name>Spring Cloud Starter Tencent Polaris Config</name>
<dependencies> <dependencies>
<!-- Spring Cloud Tencent dependencies start --> <!-- Spring Cloud Tencent dependencies start -->
@ -64,5 +65,28 @@
</dependency> </dependency>
<!-- Spring cloud dependencies start --> <!-- Spring cloud dependencies start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -51,16 +51,18 @@ public class PolarisConfigBootstrapAutoConfiguration {
} }
@Bean @Bean
public ConfigFileService configFileService(SDKContext sdkContext) { public PolarisPropertySourceManager polarisPropertySourceManager() {
return ConfigFileServiceFactory.createConfigFileService(sdkContext); return new PolarisPropertySourceManager();
} }
@Bean @Bean
public PolarisPropertySourceManager polarisPropertySourceManager() { @ConditionalOnConnectRemoteServerEnabled
return new PolarisPropertySourceManager(); public ConfigFileService configFileService(SDKContext sdkContext) {
return ConfigFileServiceFactory.createConfigFileService(sdkContext);
} }
@Bean @Bean
@ConditionalOnConnectRemoteServerEnabled
public PolarisConfigFileLocator polarisConfigFileLocator( public PolarisConfigFileLocator polarisConfigFileLocator(
PolarisConfigProperties polarisConfigProperties, PolarisConfigProperties polarisConfigProperties,
PolarisContextProperties polarisContextProperties, PolarisContextProperties polarisContextProperties,
@ -73,6 +75,7 @@ public class PolarisConfigBootstrapAutoConfiguration {
} }
@Bean @Bean
@ConditionalOnConnectRemoteServerEnabled
public ConfigurationModifier configurationModifier(PolarisConfigProperties polarisConfigProperties, public ConfigurationModifier configurationModifier(PolarisConfigProperties polarisConfigProperties,
PolarisContextProperties polarisContextProperties) { PolarisContextProperties polarisContextProperties) {
return new ConfigurationModifier(polarisConfigProperties, polarisContextProperties); return new ConfigurationModifier(polarisConfigProperties, polarisContextProperties);

@ -84,13 +84,14 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
CompositePropertySource compositePropertySource = new CompositePropertySource( CompositePropertySource compositePropertySource = new CompositePropertySource(
POLARIS_CONFIG_PROPERTY_SOURCE_NAME); POLARIS_CONFIG_PROPERTY_SOURCE_NAME);
// load spring boot default config files
initInternalConfigFiles(compositePropertySource);
// load custom config files
List<ConfigFileGroup> configFileGroups = polarisConfigProperties.getGroups(); List<ConfigFileGroup> configFileGroups = polarisConfigProperties.getGroups();
if (CollectionUtils.isEmpty(configFileGroups)) { if (CollectionUtils.isEmpty(configFileGroups)) {
return compositePropertySource; return compositePropertySource;
} }
initInternalConfigFiles(compositePropertySource);
initCustomPolarisConfigFiles(compositePropertySource, configFileGroups); initCustomPolarisConfigFiles(compositePropertySource, configFileGroups);
return compositePropertySource; return compositePropertySource;
@ -190,12 +191,10 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
// unknown extension is resolved as properties file // unknown extension is resolved as properties file
if (ConfigFileFormat.isPropertyFile(fileName) if (ConfigFileFormat.isPropertyFile(fileName)
|| ConfigFileFormat.isUnknownFile(fileName)) { || ConfigFileFormat.isUnknownFile(fileName)) {
configKVFile = configFileService.getConfigPropertiesFile(namespace, group, configKVFile = configFileService.getConfigPropertiesFile(namespace, group, fileName);
fileName);
} }
else if (ConfigFileFormat.isYamlFile(fileName)) { else if (ConfigFileFormat.isYamlFile(fileName)) {
configKVFile = configFileService.getConfigYamlFile(namespace, group, configKVFile = configFileService.getConfigYamlFile(namespace, group, fileName);
fileName);
} }
else { else {
LOGGER.warn( LOGGER.warn(

@ -34,6 +34,13 @@
"defaultValue": "", "defaultValue": "",
"description": "List of imported config files.", "description": "List of imported config files.",
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties" "sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
},
{
"name": "spring.cloud.polaris.config.connect-remote-server",
"type": "java.lang.Boolean",
"defaultValue": "true",
"description": "Whether to connect to a remote server, suitable for local development mode.",
"sourceType": "com.tencent.cloud.polaris.config.config.PolarisConfigProperties"
} }
] ]
} }

@ -0,0 +1,9 @@
spring:
application:
name: test
cloud:
polaris:
address: grpc://127.0.0.1:8091
namespace: default
config:
connect-remote-server: false

@ -24,6 +24,16 @@
<artifactId>spring-cloud-tencent-commons</artifactId> <artifactId>spring-cloud-tencent-commons</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-loadbalancer</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
@ -49,10 +59,10 @@
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.tencent.cloud</groupId> <groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-polaris-context</artifactId> <artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
@ -75,4 +85,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

@ -70,7 +70,7 @@
</developers> </developers>
<properties> <properties>
<revision>1.5.2-Greenwich.SR6</revision> <revision>1.5.3-Greenwich.SR6</revision>
<polaris.version>1.6.1</polaris.version> <polaris.version>1.6.1</polaris.version>
<!-- Dependencies --> <!-- Dependencies -->
@ -80,7 +80,7 @@
<openfeign.version>2.2.6.RELEASE</openfeign.version> <openfeign.version>2.2.6.RELEASE</openfeign.version>
<mocktio.version>4.5.1</mocktio.version> <mocktio.version>4.5.1</mocktio.version>
<byte-buddy.version>1.12.10</byte-buddy.version> <byte-buddy.version>1.12.10</byte-buddy.version>
<guava.version>31.0.1-jre</guava.version>
<!-- Maven Plugin Versions --> <!-- Maven Plugin Versions -->
<maven-source-plugin.version>3.2.0</maven-source-plugin.version> <maven-source-plugin.version>3.2.0</maven-source-plugin.version>
<flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version> <flatten-maven-plugin.version>1.2.7</flatten-maven-plugin.version>
@ -184,6 +184,32 @@
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<!-- third part framework dependencies -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<exclusions>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>animal-sniffer-annotations</artifactId>
<groupId>org.codehaus.mojo</groupId>
</exclusion>
<exclusion>
<artifactId>error_prone_annotations</artifactId>
<groupId>com.google.errorprone</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>

Loading…
Cancel
Save