From 44e3c5e224ca97eec5af4cee1c0a55cc71d44c08 Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Mon, 17 Jun 2019 18:31:50 +0800 Subject: [PATCH] refactor(nacos-api:config): Modify ConfigYype to be an enumeration class --- .../alibaba/nacos/api/config/ConfigType.java | 25 +++++++++++++------ .../annotation/NacosConfigListener.java | 8 ++++++ .../NacosConfigurationProperties.java | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java b/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java index 59081e67e..be063af83 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/ConfigType.java @@ -1,7 +1,7 @@ /* * Copyright 1999-2018 Alibaba Group Holding Ltd. * - * Licensed under the Apache License, Version 2.0 = the "License"); + * Licensed 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 * @@ -20,36 +20,45 @@ package com.alibaba.nacos.api.config; * @author liaochuntao * @date 2019-06-14 21:12 **/ -public class ConfigType { +public enum ConfigType { /** * config type is "properties" */ - public static final String PROPERTIES = "properties"; + PROPERTIES("properties"), /** * config type is "xml" */ - public static final String XML = "xml"; + XML("xml"), /** * config type is "json" */ - public static final String JSON = "json"; + JSON("json"), /** * config type is "text" */ - public static final String TEXT = "text"; + TEXT("text"), /** * config type is "html" */ - public static final String HTML = "html"; + HTML("html"), /** * config type is "yaml" */ - public static final String YAML = "yaml"; + YAML("yaml"); + String type; + + ConfigType(String type) { + this.type = type; + } + + public String getType() { + return type; + } } diff --git a/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigListener.java b/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigListener.java index dfc490385..1a4f8ab65 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigListener.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigListener.java @@ -17,6 +17,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.ConfigType; import com.alibaba.nacos.api.config.convert.NacosConfigConverter; import java.lang.annotation.*; @@ -48,6 +49,13 @@ public @interface NacosConfigListener { */ String dataId(); + /** + * Nacos Config type + * + * @return "properties" + */ + ConfigType type() default ConfigType.PROPERTIES; + /** * Specify {@link NacosConfigConverter Nacos configuraion convertor} class to convert target type instance. * diff --git a/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigurationProperties.java b/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigurationProperties.java index f486713de..9d8961055 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigurationProperties.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/annotation/NacosConfigurationProperties.java @@ -55,7 +55,7 @@ public @interface NacosConfigurationProperties { * * @return default value is false */ - String type() default ConfigType.PROPERTIES; + ConfigType type() default ConfigType.PROPERTIES; /** * It indicates the properties of current doBind bean is auto-refreshed when Nacos configuration is changed.