[ https://issues.apache.org/jira/browse/SCB-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16516537#comment-16516537 ]
ASF GitHub Bot commented on SCB-662: ------------------------------------ liubao68 closed pull request #767: [SCB-662]Using cse/servicecomb duplicate key will get list of values URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/767 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/demo/demo-schema/src/main/resources/microservice.yaml b/demo/demo-schema/src/main/resources/microservice.yaml new file mode 100644 index 000000000..92b69592c --- /dev/null +++ b/demo/demo-schema/src/main/resources/microservice.yaml @@ -0,0 +1,25 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- +cse-config-order: -1 + +cse: + test: + duplicate1: older + +servicecomb: + test: + duplicate2: older \ No newline at end of file diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java index 065a6761f..7b2add95b 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java +++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java @@ -36,6 +36,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import com.netflix.config.DynamicPropertyFactory; + public class SpringmvcClient { private static RestTemplate templateUrlWithServiceName = new CseRestTemplate(); @@ -53,6 +55,8 @@ public static void main(String[] args) throws Exception { } public static void run() { + testConfigurationDuplicate(); + templateUrlWithServiceName.setRequestFactory(new UrlWithServiceNameClientHttpRequestFactory()); restTemplate = RestTemplateBuilder.create(); controller = BeanUtils.getBean("controller"); @@ -198,4 +202,19 @@ private static void testController() { user.setName("world"); TestMgr.check("ha world", controller.saySomething("ha", user)); } + + private static void testConfigurationDuplicate() { + // this configuration will give warning messages: + // Key servicecomb.test.duplicate2 with an ambiguous item cse.test.duplicate2 exists, please use the same prefix or will get unexpected merged value. + // Key servicecomb.test.duplicate1 with an ambiguous item cse.test.duplicate1 exists, please use the same prefix or will get unexpected merged value. + // and the expected value is not quite determined. But will not get wrong value like 'older,newer' or 'newer,older' + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("cse.test.duplicate2", "wrong").get(), + "newer"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.test.duplicate2", "wrong").get(), + "older"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("cse.test.duplicate1", "wrong").get(), + "older"); + TestMgr.check(DynamicPropertyFactory.getInstance().getStringProperty("servicecomb.test.duplicate1", "wrong").get(), + "newer"); + } } diff --git a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml index 541a8c714..8dc482433 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml +++ b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml @@ -80,6 +80,12 @@ servicecomb: region: my-Region availableZone: my-Zone + test: + duplicate1: newer + +cse: + test: + duplicate2: newer #########SSL options ssl.protocols: TLSv1.2 ssl.authPeer: true diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java index f8b52717a..8f8922dcb 100644 --- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java +++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/ConfigUtil.java @@ -171,7 +171,14 @@ private static void duplicateServiceCombConfigToCse(AbstractConfiguration source } String cseKey = CONFIG_CSE_PREFIX + key.substring(key.indexOf(".") + 1); - source.addProperty(cseKey, source.getProperty(key)); + if (!source.containsKey(cseKey)) { + source.addProperty(cseKey, source.getProperty(key)); + } else { + LOGGER + .warn( + "Key {} with an ambiguous item {} exists, please use the same prefix or will get unexpected merged value.", + key, cseKey); + } } } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Using cse/servicecomb duplicate key will get list of values > ----------------------------------------------------------- > > Key: SCB-662 > URL: https://issues.apache.org/jira/browse/SCB-662 > Project: Apache ServiceComb > Issue Type: Bug > Reporter: liubao > Priority: Major > > config file 1: > cse.test.value=a > > config file 2: > servicecomb.test.value=b > > when get value, will get a,b not a nor b. -- This message was sent by Atlassian JIRA (v7.6.3#76005)