使用SpringBoot的配置中心客户端0.2.7 api的时候发现两个问题.
Two issues I found in spring-boot client api when use the feature of Config Center
当在SpringBoot启动类上标@NacosPropertySource注解, 指定dataId的名字中包含点的时候,启动报错
An exception occured when the value of property "dataId" defined in the annotation @NacosPropertySource contains a dot - "." while the bootstrap main class is annotated with this annotation.
例子: @NacosPropertySource(dataId="study.nacos.boot"), 启动会报如下错误
For instance: After the main class is annotated with @NacosPropertySource(dataId="study.nacos.boot"), the following Exception is occured
java.lang.UnsupportedOperationException: Parsing is not yet supported for this type profile : boot
报错代码位置: com.alibaba.nacos.spring.util.ConfigParseUtils.toProperties(ConfigParseUtils.java:100)
The error root stack is: com.alibaba.nacos.spring.util.ConfigParseUtils.toProperties(ConfigParseUtils.java:100)
经过我调式源码, 发现引起报这个错的的代码的类
After my debug, I found the root cause in this class
关键位置为173行的代码, 方法 protected NacosPropertySource doBuild
The key cause is at line 173 in method: protected NacosPropertySource doBuild
String type = ((ConfigType) runtimeAttributes.get(CONFIG_TYPE_ATTRIBUTE_NAME))
.getType();
dataId = NacosUtils.readFromEnvironment(dataId, environment);
groupId = NacosUtils.readFromEnvironment(groupId, environment);
// 这个是173行
// this is line 173
type = StringUtils.isEmpty(NacosUtils.readTypeFromDataId(dataId)) ? type
: NacosUtils.readTypeFromDataId(dataId);
- 问题还在173行中调用的 NacosUtils.readTypeFromDataId 这个方法, 代码内容如下
The code in at line 173 calls another method NacosUtils.readTypeFromDataId, the method body is
```java
// 把dataId的值 study.nacos.boot 代入到这个方法的时候, 方法返回字符串 boot
// Pass the value "study.nacos.boot" of dataId to this method, a string value "boot" is returned.
// 方法执行完后返回到 AbstractNacosPropertySourceBuilder 类的 173行, type值就由 properties 变成了 boot
// After the method invocation, code go back to line 173 of class AbstractNacosPropertySourceBuilder, the value of variable type is changed to "boot"
public static String readTypeFromDataId(String dataId) {
if (StringUtils.isEmpty(dataId)) {
return dataId;
}
int index = dataId.lastIndexOf(".");
return index != -1 ? dataId.substring(index + 1) : "";
}
于是导致了后续在调用 ConfigParseUtils.toProperties方法的时候, 不支持type为boot的的解析了
So the exception appears later when calling method ConfigParseUtils.toProperties
第一个问题现象就描述完了, 本来想说点猜测的想法, 不过想了想, 还是不在各位大神面前得瑟了 ^_^
That's the first issue I found.
这个问题在使用spring boot配置文件里直接配, 不会出现
But it doesn't appears when the project is configured with spring boot configuration file: application.properties
还是在使用 @NacosPropertySource 标在启动类上的时候, 在Nacos控制台里修改完配置项, 工程中不会实时更新, autoRefresh已经指定过true了
The auto refresh is not fired when the project is configured with @NacosPropertySource.
同样这个问题在使用spring boot配置文件里直接配的时候, 也不会出现
But it does fire when configured with spring boot configuration file.
Issue Description
Type: bug report
Describe what happened
使用SpringBoot的配置中心客户端0.2.7 api的时候发现两个问题. Two issues I found in spring-boot client api when use the feature of Config Center
例子: @NacosPropertySource(dataId="study.nacos.boot"), 启动会报如下错误 For instance: After the main class is annotated with @NacosPropertySource(dataId="study.nacos.boot"), the following Exception is occured java.lang.UnsupportedOperationException: Parsing is not yet supported for this type profile : boot
报错代码位置: com.alibaba.nacos.spring.util.ConfigParseUtils.toProperties(ConfigParseUtils.java:100) The error root stack is: com.alibaba.nacos.spring.util.ConfigParseUtils.toProperties(ConfigParseUtils.java:100)
经过我调式源码, 发现引起报这个错的的代码的类
After my debug, I found the root cause in this class
关键位置为173行的代码, 方法 protected NacosPropertySource doBuild The key cause is at line 173 in method: protected NacosPropertySource doBuild
dataId = NacosUtils.readFromEnvironment(dataId, environment); groupId = NacosUtils.readFromEnvironment(groupId, environment); // 这个是173行 // this is line 173 type = StringUtils.isEmpty(NacosUtils.readTypeFromDataId(dataId)) ? type : NacosUtils.readTypeFromDataId(dataId);
第一个问题现象就描述完了, 本来想说点猜测的想法, 不过想了想, 还是不在各位大神面前得瑟了 ^_^ That's the first issue I found.
这个问题在使用spring boot配置文件里直接配, 不会出现 But it doesn't appears when the project is configured with spring boot configuration file: application.properties
同样这个问题在使用spring boot配置文件里直接配的时候, 也不会出现 But it does fire when configured with spring boot configuration file.
Describe what you expected to happen
第一个问题的期望, 当然是正常启动不报错 第二个问题的期望, 当在nacos里修改过dataId的内容时, 工程里可以实时更新
How to reproduce it (as minimally and precisely as possible)
issue 1:
issue 2: 直接测试就成
I don't want to translate the reproducing part any more, sorry to foreign guys.
Tell us your environment
OS: MacOS 10.13.4 JAR Library Version: com.alibaba.boot:nacos-config-spring-boot-starter:0.2.7 Nacos Server Version: 1.2.1
题外话 Other things I'd like to say
我个人感觉现现在汉语也热了, 咱们应该鼓励老外学汉语. The project owner encourages we using English, but I encourage you guys study Chinese.
Anything else we need to know?
Nothing else, thank you.