You need to use nacos to inject a map object into the bean. If you use nacos directly, you need to open a ****.json configuration file, which is too much trouble for me personally. Combined with the function of Spring EL expressions, this function is simply realized.
java code
@Value("#{T(com.alibaba.fastjson.JSON).parseObject(${tyc.appid.token.map}, T(java.util.Map))}")
private Map<String, String> tokenMap;
nacos configuration
tyc.appid.token.map='{"shuffle":"token1", "msign":"token2"}'
Spring EL syntax description
- The T operator can be used to specify the installation of a java.lang.ClassClass (the type). Static methods can also be called using this operator
- Expression format in xml or annotation: #{<expression string>}
- ${placeholder} represents a placeholder
Grammar reference: https://itmyhome.com/spring/expressions.html