Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirng 中nacosvalue注解内进行split获取list结果异常 #4027

Closed
FengJinghHua opened this issue Oct 20, 2020 · 7 comments
Closed

spirng 中nacosvalue注解内进行split获取list结果异常 #4027

FengJinghHua opened this issue Oct 20, 2020 · 7 comments

Comments

@FengJinghHua
Copy link

spring中@value注解可以进行string的split并赋值为list对象,如下:
@value("#{'${support.type}'.split(',')}")
Set supportType;

这个在@nacosValue中应该如何写才能得到对应效果?please help
我试过
@NacosValue(value = "${support.type:,#}split(',')}",
autoRefreshed = true)
但是取到的值是["
","#}split(", "')}"] 而不是 ["*", "#"]
please help,thanks

@KomachiSion
Copy link
Collaborator

nacosValue应该不支持这个操作。

@FengJinghHua
Copy link
Author

@KomachiSion ok~ 我试过在赋值是给了string类型,然后再指定一个list类型,如下:

@NacosValue(value = "${support.type:,#)}",
autoRefreshed = true)
String type1;
private List familyList = Arrays.asList(type1.split(","));

不幸的是,启动的时候会报空指针异常,是和nacos启动时机有关系吗,或者说,如果要实现类似@value split 的功能,有workaround吗

@KomachiSion
Copy link
Collaborator

应该和启动顺序有关。

是否实现类似的功能需要看社区的反馈,看看是否社区中有人愿意贡献,如果社区里需求的人数比较多,我们也会提高这个功能的优先级。

@horizonzy
Copy link
Collaborator

@KomachiSion ok~ 我试过在赋值是给了string类型,然后再指定一个list类型,如下:

@NacosValue(value = "${support.type:,#)}",
autoRefreshed = true)
String type1;
private List familyList = Arrays.asList(type1.split(","));

不幸的是,启动的时候会报空指针异常,是和nacos启动时机有关系吗,或者说,如果要实现类似@value split 的功能,有workaround吗

这个我来搞搞,和spring一样支持el表达式是吗。

@FengJinghHua
Copy link
Author

@horizonzy 是的,这样的使用应该很普遍

@horizonzy
Copy link
Collaborator

这个PR. nacos-group/nacos-spring-project#237

@horizonzy
Copy link
Collaborator

@horizonzy 是的,这样的使用应该很普遍

Hi, 最新的代码已经被合到nacos-spring-project,如果想要使用这个特性的话,可以单独对nacos-spring-project打包使用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants