forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a29bf24
commit 1145260
Showing
20 changed files
with
161 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,8 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.nacos.api.config.annotation; | ||
package com.alibaba.nacos.api.annotation; | ||
|
||
import com.alibaba.nacos.api.PropertyKeyConst; | ||
import com.alibaba.nacos.api.config.ConfigService; | ||
import com.alibaba.nacos.api.naming.NamingService; | ||
|
||
|
@@ -28,17 +27,16 @@ | |
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see ConfigService | ||
* @see NamingService | ||
* @see PropertyKeyConst | ||
* @since 0.1.0 | ||
* @see NacosProperties | ||
* @since 0.2.1 | ||
*/ | ||
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface NacosInjected { | ||
|
||
/** | ||
* The {@link NacosProperties} attribute, If not specified, it will use | ||
* global Nacos Properties global Nacos Properties}. | ||
* The {@link NacosProperties} attribute, If not specified, it will use global Nacos Properties. | ||
* | ||
* @return the default value is {@link NacosProperties} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.nacos.api.config.annotation; | ||
package com.alibaba.nacos.api.annotation; | ||
|
||
import com.alibaba.nacos.api.PropertyKeyConst; | ||
|
||
|
@@ -25,7 +25,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see PropertyKeyConst | ||
* @since 0.1.0 | ||
* @since 0.2.1 | ||
*/ | ||
@Target(ElementType.ANNOTATION_TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
@@ -77,60 +77,108 @@ | |
*/ | ||
String ENCODE = "encode"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>"${nacos.endpoint:}"</code> | ||
*/ | ||
String ENDPOINT_PLACEHOLDER = "${" + PREFIX + ENDPOINT + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>"${nacos.namespace:}"</code> | ||
*/ | ||
String NAMESPACE_PLACEHOLDER = "${" + PREFIX + NAMESPACE + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>"${nacos.access-key:}"</code> | ||
*/ | ||
String ACCESS_KEY_PLACEHOLDER = "${" + PREFIX + ACCESS_KEY + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>"${nacos.secret-key:}"</code> | ||
*/ | ||
String SECRET_KEY_PLACEHOLDER = "${" + PREFIX + SECRET_KEY + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>${nacos.server-addr:}"</code> | ||
*/ | ||
String SERVER_ADDR_PLACEHOLDER = "${" + PREFIX + SERVER_ADDR + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is ${nacos.context-path:}" | ||
*/ | ||
String CONTEXT_PATH_PLACEHOLDER = "${" + PREFIX + CONTEXT_PATH + ":}"; | ||
|
||
/** | ||
* The placeholder of endpoint, the value is <code>"${nacos.cluster-name:}"</code> | ||
*/ | ||
String CLUSTER_NAME_PLACEHOLDER = "${" + PREFIX + CLUSTER_NAME + ":}"; | ||
|
||
/** | ||
* The placeholder of {@link NacosProperties#ENCODE encode}, the value is <code>"${nacos.encode:UTF-8}"</code> | ||
*/ | ||
String ENCODE_PLACEHOLDER = "${" + PREFIX + ENCODE + ":UTF-8}"; | ||
|
||
/** | ||
* The property of "endpoint" | ||
* | ||
* @return empty as default value | ||
* @see #ENDPOINT_PLACEHOLDER | ||
*/ | ||
String endpoint() default "${" + PREFIX + ENDPOINT + ":}"; | ||
String endpoint() default ENDPOINT_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "namespace" | ||
* | ||
* @return empty as default value | ||
* @see #NAMESPACE_PLACEHOLDER | ||
*/ | ||
String namespace() default "${" + PREFIX + NAMESPACE + ":}"; | ||
String namespace() default NAMESPACE_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "access-key" | ||
* | ||
* @return empty as default value | ||
* @see #ACCESS_KEY_PLACEHOLDER | ||
*/ | ||
String accessKey() default "${" + PREFIX + ACCESS_KEY + ":}"; | ||
String accessKey() default ACCESS_KEY_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "secret-key" | ||
* | ||
* @return empty as default value | ||
* @see #SECRET_KEY_PLACEHOLDER | ||
*/ | ||
String secretKey() default "${" + PREFIX + SECRET_KEY + ":}"; | ||
String secretKey() default SECRET_KEY_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "server-addr" | ||
* | ||
* @return empty as default value | ||
* @see #SERVER_ADDR_PLACEHOLDER | ||
*/ | ||
String serverAddr() default "${" + PREFIX + SERVER_ADDR + ":}"; | ||
String serverAddr() default SERVER_ADDR_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "context-path" | ||
* | ||
* @return empty as default value | ||
* @see #CONTEXT_PATH_PLACEHOLDER | ||
*/ | ||
String contextPath() default "${" + PREFIX + CONTEXT_PATH + ":}"; | ||
String contextPath() default CONTEXT_PATH_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "cluster-name" | ||
* | ||
* @return empty as default value | ||
* @see #CLUSTER_NAME_PLACEHOLDER | ||
*/ | ||
String clusterName() default "${" + PREFIX + CLUSTER_NAME + ":}"; | ||
String clusterName() default CLUSTER_NAME_PLACEHOLDER; | ||
|
||
/** | ||
* The property of "encode" | ||
* | ||
* @return "UTF-8" as default value | ||
* @see #ENCODE_PLACEHOLDER | ||
*/ | ||
String encode() default "${" + PREFIX + ENCODE + ":UTF-8}"; | ||
String encode() default ENCODE_PLACEHOLDER; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
*/ | ||
package com.alibaba.nacos.api.config.annotation; | ||
|
||
import com.alibaba.nacos.api.annotation.NacosProperties; | ||
import com.alibaba.nacos.api.common.Constants; | ||
import com.alibaba.nacos.api.config.convert.NacosConfigConverter; | ||
|
||
|
@@ -27,7 +28,7 @@ | |
* Annotation that marks a method as a listener for Nacos Config change. | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package com.alibaba.nacos.api.config.annotation; | ||
|
||
import com.alibaba.nacos.api.PropertyKeyConst; | ||
import com.alibaba.nacos.api.annotation.NacosProperties; | ||
import com.alibaba.nacos.api.common.Constants; | ||
|
||
import java.lang.annotation.*; | ||
|
@@ -29,7 +30,7 @@ | |
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see PropertyKeyConst | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see NacosConfigurationProperties | ||
* @see NacosProperty | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
@Target({ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @see NacosConfigurationProperties | ||
* @see NacosIgnore | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
@Target({ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
* Annotation which extends value to support auto-refresh | ||
* | ||
* @author <a href="mailto:[email protected]">hxy1991</a> | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
* | ||
* @param <T> the target type that wanted | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @since 0.1.0 | ||
* @since 0.2.0 | ||
*/ | ||
public interface NacosConfigConverter<T> { | ||
|
||
|
78 changes: 78 additions & 0 deletions
78
api/src/test/java/com/alibaba/nacos/api/annotation/NacosPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package com.alibaba.nacos.api.annotation; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.mock.env.MockEnvironment; | ||
|
||
import static com.alibaba.nacos.api.annotation.NacosProperties.*; | ||
|
||
/** | ||
* {@link NacosProperties} Test | ||
* | ||
* @author <a href="mailto:[email protected]">Mercy</a> | ||
* @since 0.2.1 | ||
*/ | ||
public class NacosPropertiesTest { | ||
|
||
@Test | ||
public void testPlaceholders() { | ||
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER); | ||
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER); | ||
} | ||
|
||
@Test | ||
public void testResolvePlaceholders() { | ||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value"); | ||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "nacos.namespace", "test-value", "test-value"); | ||
testResolvePlaceholder(NAMESPACE_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "nacos.access-key", "test-value", "test-value"); | ||
testResolvePlaceholder(ACCESS_KEY_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "nacos.secret-key", "test-value", "test-value"); | ||
testResolvePlaceholder(SECRET_KEY_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "nacos.server-addr", "test-value", "test-value"); | ||
testResolvePlaceholder(SERVER_ADDR_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "nacos.context-path", "test-value", "test-value"); | ||
testResolvePlaceholder(CONTEXT_PATH_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "nacos.cluster-name", "test-value", "test-value"); | ||
testResolvePlaceholder(CLUSTER_NAME_PLACEHOLDER, "", "test-value", ""); | ||
|
||
testResolvePlaceholder(ENCODE_PLACEHOLDER, "nacos.encode", "test-value", "test-value"); | ||
testResolvePlaceholder(ENCODE_PLACEHOLDER, "", "test-value", "UTF-8"); | ||
} | ||
|
||
private void testResolvePlaceholder(String placeholder, String propertyName, String propertyValue, String expectValue) { | ||
MockEnvironment environment = new MockEnvironment(); | ||
environment.setProperty(propertyName, propertyValue); | ||
String resolvedValue = environment.resolvePlaceholders(placeholder); | ||
Assert.assertEquals(expectValue, resolvedValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.